我在 EC2 上运行 node.js 和 socket.io,使用 nginx v1.4.1
这是我的 /etc/nginx/sites-available/default
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name mysite.com;
location / {
proxy_pass http://localhost:4321;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
但是我得到
WebSocket connection to 'ws://mysite.com/socket.io/1/websocket/nS7f2eI5jAZ-pIN_8fai' failed: Unexpected response code: 502
并从节点:
debug - setting request GET /socket.io/1/websocket/nS7f2eI5jAZ-pIN_8fai
debug - set heartbeat interval for client nS7f2eI5jAZ-pIN_8fai
warn - websocket connection invalid
然后它切换到 xhr-polling。
我完全遵循了这么多在线指南关于 Nginx + websocket 的说法,但我不知道我在哪里犯了错误。