最近項目上有一個需求,需要轉(zhuǎn)發(fā)的后端,不是內(nèi)網(wǎng)服務(wù)器,而是互聯(lián)網(wǎng)可以訪問的一個域名。
按照之前方式配置好了,訪問一直是 502 Bad Gateway錯誤,搜索解決的方案大都是selinux配置配置問題,實際上selinux都是關(guān)閉的。

在服務(wù)器上使用 curl https://www.xxx.com ,可以正常訪問。
解決方案:
location /test/ {
proxy_pass http://網(wǎng)址信息/test/;
proxy_buffering off;
proxy_redirect off;
proxy_read_timeout 86400;
proxy_connect_timeout 120;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host 網(wǎng)址信息;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root html;
index index.html index.htm;
client_max_body_size 200m;
}
proxy_set_header Host 后面的配置項,必須要和 proxy_pass 配置項中的網(wǎng)址信息是一樣的,即可解決。