使用proxy_pass時,如果最后面加上"/",則請求后端服務時會自動去除匹配規則中的uri。
location ^~/appws/ {
# appws結尾不帶"/",實際請求服務器時不會去掉"/appws"
proxy_pass http://appws;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; # 升級協議頭
proxy_set_header Connection upgrade;
}
假設域名為wss://www.baidu.com
請求wss://www.baidu.com/appws
使用nginx代理因為使用"/"斜杠,會把匹配規則中的uri移除掉
實際到達后端服務請求的uri是:
wss://www.baidu.com