部署vue项目到nginx
修改nginx的配置文件
增加如下配置:
#ssl配置省略
location /api {
rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://ip:port;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
rewrite 指令的作用
rewrite指令可以实现URL重写。
因为前端传递的都是以api开头的请求地址,但是后端接口地址不是api开头,所有需要将请求地址重写,去掉api。
参考:
地址重写:https://www.cnblogs.com/tugenhua0707/p/10798762.html

1832

被折叠的 条评论
为什么被折叠?



