利用Nginx处理Vue开发环境的跨域的方法
1. 需求
本地测试域名与线上域名相同,以便正确传递 Cookie 和进行 SSO 测试。
注:由于 SSO 登录后,相关 Cookie 被加在四级域名上,因而需要做到本地测试域名和线上接口域名相同。
2. 方案
配置 Host 文件使线上域名指向 Localhost:
127.0.0.1 product.xxx.xxx.com
配置 Nginx 进行对应转发:
server {
listen 80;
listen [::]:80;
server_name ${product.xxx.xxx.com};
location /api {
proxy_pass https://${ip.ip.ip.ip};
proxy_set_header Host $host;
}
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
}
}配置 vue.config.js 以免出现 Invalid Host header 报错:
{
devServer: {
disableHostCheck: true
}
} 相关推荐
liwf 2020-04-20
Jaystrong 2020-08-02
gaogaorimu 2020-07-18
FanErZong 2020-07-18
liwf 2020-07-09
thatway 2020-06-28
糊一笑 2020-06-27
tangjianft 2020-06-25
86284851 2020-06-16
LUOPING0 2020-06-16
sshong 2020-06-12
wys 2020-06-10
mmyCSDN 2020-05-28
fanhuasijin 2020-05-28