刚开始我访问 sockets.jiyinyiyong.info
并在浏览器里连接 socket 没有成功,
浏览器端出现报错
Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'
服务器上的信息是:
a connection
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - websocket writing 5:::{"name":"cast"}
debug - setting request GET /socket.io/1/xhr-polling/11404802851312554938?t=1344062033928
debug - setting poll timeout
debug - discarding transport
debug - cleared heartbeat interval for client 11404802851312554938
debug - clearing poll timeout
debug - xhr-polling writing 5:::{"name":"cast"}
debug - set close timeout for client 11404802851312554938
我搜到的问题大致说浏览器那个错误是因为 header 被破破坏了…
http://stackoverflow.com/questions/6576403/websocket-handshake-failing-in-webkit-with-socket-io-0-7
http://stackoverflow.com/questions/6769342/websockets-handshake-problem
就怀疑到 Nginx 上去了, 想起来以前也遇到过…
就测试 jiyinyiyong.info:8000
去访问, 也 io.connect() 这个网址, 再就能显示了…
照这样问题就出在 Nginx 的配置上边了, 不怎么懂 Nginx, 求助啊,
下面是我出错的时候的配置:
upstream sockets {
server 127.0.0.1:8005;
}
server {
listen 0.0.0.0:80;
server_name sockets.jiyinyiyong.info;
access_log /var/log/nginx/sockets.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://sockets;
proxy_redirect off;
}
}
13 回复
hi~ @yaryin,我不清楚你是在哪里报错了。我当时就是按照 https://github.com/yaoweibin/nginx_tcp_proxy_module#readme 的方法,把里面patch和configure 的路径换成你下载的位置就可以了。