nginx代理WebSocket無法訪問ws//WebSocket/xxxx
阿新 • • 發佈:2018-12-30
NGINX通過允許一個在客戶端和後端伺服器之間建立的隧道來支援WebSocket。為了NGINX傳送來至於客戶端Upgrade請求到後端伺服器,Upgrade和Connection頭部必須被設定明確。
示例,這裡我們使用nginx來做代理。
upstream wsbackend {
server 127.0.0.1:3000;
}
server {
listen 8090;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# location / {
# root html;
# index index.html index.htm;
# }
location / {
proxy_pass http://wsbackend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade" ;
}
}