为了解决跨域问题,真实模拟未来实地程序部署形态,在开发机器上配置nginx分别代理vue前端和springboot后台项目,配置参数如下:
location / {
add_header Cache-Control 'no-store, no-cache'; #// 设置不缓存
proxy_pass http://127.0.0.1:9527;
}
location ^~ /xxx/api/ {
rewrite ^.+xxx/api/?(.*)$ /$1 break;
include uwsgi_params;
proxy_pass http://127.0.0.1:8082/xxx/;
}
location / 配置为无条件转发给webstorm跑的9527端口
location ^~ /xxx/api 配置为代理后台springboot项目的代理路径,因为后台springboot项目上下文路径名称叫xxx,所以这里还需要对/xxx/api的请求路径做个重写替换。