一開始了解了一下網上說什么靜態文件不能用post只能用get訪問,所以后來配置了nginx的反向代理,雖然在vue的devserver可以配置proxy,但是那只針對於開發環境,生產環境無效,具體代碼如下,希望可以幫助大家:
server {
listen 8082;
server_name localhost;
location /{
root E:/DevSoft/nginx-1.17.7/html/dist;
index index.html index.htm;
#不寫這句,history模式請求路由會變成直接請求后台的路由導致404
try_files $uri $uri/ /index.html;
autoindex on;
}
#反向代理,解決跨域問題,不配置的話也容易出現405的問題
location ~/api/{
proxy_pass http://localhost:49449;
}
location ~/connect/token{
proxy_pass http://192.168.150.129:8080;
}
}
