vue 部署后 405 not allowed"/>
vue 部署后 405 not allowed
关于部署vue项目dist包,在nginx配置遇到的坑:
1.vue项目中vue.config.js的配置:devServer.proxy
可以是一个指向开发环境 API 服务器的字符串:
evServer: {proxy: {'/prod-api': {target: 'http://192.168.0.68:38090;',changeOrigin: true,pathRewrite: {'^/prod-api': '' // 将/prod-api 替换为空}},}
},
2.打包后dist包部署到linux服务器上,Nginx配置反向代理实现ajax进行跨域访问:
conf目录下nginx.conf配置如下:
server {listen 38081;server_name 192.168.159.133;location / {root /home/frontweb/dist; #dist包部署路径try_files $uri $uri/ /index.html last;index index.html index.htm;}#反向代理location /prod-api {rewrite ^/prod-api/(.*)$ /$1 break; # /prod-api/ 替换为/,因为后台接口无/prod-apiproxy_pass http://192.168.159.134:38090; #后台接口地址proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $remote_addr;}location @router{rewrite ^.*$ /index.html last;}
}
配置之后重启nginx即可 ./nginx -s reload
注意:开始漏了rewrite ^/prod-api/(.*)$ /$1 break; 请求后台接口一直404 not found,
更多推荐
vue 部署后 405 not allowed
发布评论