vue 部署后 405 not allowed

编程入门 行业动态 更新时间:2024-10-26 22:20:06

<a href=https://www.elefans.com/category/jswz/34/1770550.html style=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

本文发布于:2023-12-06 23:13:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1669285.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:vue   allowed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!