如果 websocket 中間有反向代理服務器,是不能直接通信的,需要進行配置,以下配置均在 nginx.conf 文件中進行。
首先在 http 節點下新增:
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
}
然后在相應的 server 節點下新增:
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 8020;
server_name localhost;
location / {
proxy_pass http://localhost:8010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
}
}
大概是這樣,然后就可以了~