nginx未配置proxy
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
背景前端vue和后端java放在一台机器上nginx做请求转发。用户未登录状态下会返回给前端信息。前端判断后发起登录校验请求。
else if (res.code == 401 || res.code==402) {
if(res.data.sso){
// debugger;
console.log(“—”,response.data.data);
window.location.href = res.data.sso;
}
//debugger;
return Promise.reject(response || “error”);
}
然后nginx来做请求转发发现此时一直请求失败。
原因nginx请求转发时没有携带之前客户端的请求头信息导致请求失败。
nginx需要配置 proxy_set_header Host $host; 转发时会把请求头信息也带上。此时就可以了
server {
listen 80;
server_name test-xxx.xxx.com ;
access_log /data/logs/access_userlevel.log main;
error_log /data/logs/error_userlevel.log;
root /data/apps/ysdq-userlevel-front/front;
index index.html;
location /api/ {
proxy_pass http://xxx:xxx/api/;
proxy_set_header Host $host;
}
location /sso/ {
proxy_pass http://xxx:xxx/sso/;
proxy_set_header Host $host;
}
}
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |