嗨我想配置nginx作爲websockets的反向代理。配置我的服務器如下:nginx websocket反向代理配置
server {
listen 80;
server_name www.mydomain.com;
access_log off;
#error_log off;
location/{
proxy_pass http://127.0.0.1:8765;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_buffering off;
}
}
,但我得到一個錯誤,從客戶端像下面
WebSocket連接到「WS://www.application.com/ws」失敗:WebSocket的握手過程中的錯誤: '連接'標題值不是'升級'
我可能做了一些配置錯誤,但我看不到它。
客戶端請求頭是繼
GET ws://www.talkybee.com/ws HTTP/1.1
Pragma: no-cache
Origin: http://www.talkybee.com
Host: www.talkybee.com
Sec-WebSocket-Key: Ol+O1IdaLEsHxxWRBt2oqg==
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
Upgrade: websocket
Sec-WebSocket-Extensions: x-webkit-deflate-frame
Cache-Control: no-cache
Connection: Upgrade
Sec-WebSocket-Version: 13
當我做一個正常的直接連接,我的連接只是工作。這是工作請求頭。
Cache-Control:no-cache
Connection:Upgrade
Host:www.talkybee.com:8765
Origin:http://www.talkybee.com:8765
Pragma:no-cache
Sec-WebSocket-Extensions:x-webkit-deflate-frame
Sec-WebSocket-Key:Y026b/84aUkMxVb0MaKE2A==
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
如果您只是嘗試'proxy_pass http://127.0.0.1:8765 /;會發生什麼情況' – rednaw
@rednaw我得到同樣的例外。我改變了當前問題中的配置。 – yilmazhuseyin
你的客戶是否也將'Connection'頭設置爲'Upgrade'? – rednaw