Nginx不能轉發帶有websocket功能的專案解決方案
阿新 • • 發佈:2019-01-10
最近在做websocket推送日誌到前臺頁面,部署伺服器是用nginx轉發後無法連線websocket,而且我的nginx還是帶https證書的,下面轉發的配置可以解決這一問題(僅供參考)
#將/xcloud-api請求轉發給http://127.0.0.1:8012處理 location /xcloud-api { proxy_pass http://127.0.0.1:8012/xcloud-api; #這裡的埠記得改成專案對應的哦 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; proxy_set_header Host $host; proxy_http_version 1.1; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Origin ""; proxy_redirect off; }
主要是這三個配置
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";