最近項目上有一個需求,需要轉發(fā)的后端,不是內(nèi)網(wǎng)服務器,而是互聯(lián)網(wǎng)可以訪問的一個域名。

按照之前方式配置好了,訪問一直是 502 Bad Gateway錯誤,搜索解決的方案大都是selinux配置配置問題,實際上selinux都是關閉的。

解決nginx轉發(fā)后端域名,出現(xiàn)502 Bad Gateway錯誤

在服務器上使用 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)址信息是一樣的,即可解決。

相關文章

發(fā)表回復

您的郵箱地址不會被公開。 必填項已用 * 標注

聯(lián)系電話

176-8951-1878

微信
微信
分享本頁
返回頂部
西藏巨騰信息技術有限公司提供拉薩網(wǎng)站建設、軟件開發(fā)、小程序開發(fā)、APP開發(fā)、網(wǎng)絡營銷、在線推廣、在線商城開發(fā)等服務,聯(lián)系電話: 17689511878