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

在服務(wù)器上使用 curl https://www.xxx.com ,可以正常訪(fǎng)問(wèn)。
解決方案:
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 后面的配置項(xiàng),必須要和 proxy_pass 配置項(xiàng)中的網(wǎng)址信息是一樣的,即可解決。