我正在使用nginx 1.4.1,我正在尝试配置它以使用socket.io websockets。我认为我已经正确完成了,因为我看到'握手授权',但几秒钟后socket.io开始使用xhr-polling,jsonp-polling并且无法正常工作。
我的node.js表达app在localhost:3002上运行。我使用nginx来反向代理到这个应用程序。 Socket.io也在同一个端口上侦听。
我试图在SO和其他地方跟踪许多指南,但我无法让它工作。需要专家的帮助。我也通过错误登录放在这里,不确定它是否会有所帮助。
nginx.conf:
upstream instaneous {
server 127.0.0.1:3002;
}
server {
listen 80;
server_name instaneous.pin.gs;
access_log logs/instaneous.access.log;
error_log logs/instaneous.error.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://instaneous;
proxy_redirect off;
# enables WS support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
node.js socket.io log
debug - client authorized
info - handshake authorized Z7CX6-3PIUStxILeiTk3
debug - setting request GET /socket.io/1/websocket/Z7CX6-3PIUStxILeiTk3
debug - set heartbeat interval for client Z7CX6-3PIUStxILeiTk3
debug - client authorized for
debug - websocket writing 1::
debug - setting request GET /socket.io/1/xhr-polling/Z7CX6-3PIUStxILeiTk3?t=1373509382625
debug - setting poll timeout
debug - discarding transport
debug - cleared heartbeat interval for client Z7CX6-3PIUStxILeiTk3
debug - setting request GET /socket.io/1/jsonp-polling/Z7CX6-3PIUStxILeiTk3?t=1373509392627&i=0
debug - setting poll timeout
debug - discarding transport
debug - clearing poll timeout
debug - clearing poll timeout
debug - jsonppolling writing io.j[0]("8::");
debug - set close timeout for client Z7CX6-3PIUStxILeiTk3
debug - jsonppolling closed due to exceeded duration
debug - setting request GET /socket.io/1/jsonp-polling/Z7CX6-3PIUStxILeiTk3?t=1373509412768&i=0
debug - setting poll timeout
debug - discarding transport
debug - cleared close timeout for client Z7CX6-3PIUStxILeiTk3
debug - jsonppolling received data packet 5:::{"name":"join","args":["abcdef"]}
{ '': [ 'Z7CX6-3PIUStxILeiTk3' ],
'/abcdef': [ 'Z7CX6-3PIUStxILeiTk3' ] }
debug - clearing poll timeout
debug - jsonppolling writing io.j[0]("8::");
debug - set close timeout for client Z7CX6-3PIUStxILeiTk3
debug - jsonppolling closed due to exceeded duration
debug - client authorized
info - handshake authorized BLbSS3QLgn54BThtiTk4
debug - client authorized
info - handshake authorized 6TOdYiYsxIz_b19GiTk5
instaneous.error.log
2013/07/11 04:01:49 [error] 406#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 220.255.2.143, server: instaneous.pin.gs, request: "GET /socket.io/1/xhr-polling/AFH6aS6ku3hM36qH49dI?t=1373515290708 HTTP/1.1", upstream: "http://127.0.0.1:3002/socket.io/1/xhr-polling/AFH6aS6ku3hM36qH49dI?t=1373515290708", host: "instaneous.pin.gs", referrer: "http://instaneous.pin.gs/"
2013/07/11 04:01:49 [error] 406#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 220.255.2.163, server: instaneous.pin.gs, request: "GET /socket.io/1/jsonp-polling/AFH6aS6ku3hM36qH49dI?t=1373515300709&i=0 HTTP/1.1", upstream: "http://127.0.0.1:3002/socket.io/1/jsonp-polling/AFH6aS6ku3hM36qH49dI?t=1373515300709&i=0", host: "instaneous.pin.gs", referrer: "http://instaneous.pin.gs/"
2013/07/11 04:01:49 [error] 406#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 220.255.2.143, server: instaneous.pin.gs, request: "POST /socket.io/1/jsonp-polling/AFH6aS6ku3hM36qH49dI?t=1373515309646&i=0 HTTP/1.1", upstream: "http://127.0.0.1:3002/socket.io/1/jsonp-polling/AFH6aS6ku3hM36qH49dI?t=1373515309646&i=0", host: "instaneous.pin.gs", referrer: "http://instaneous.pin.gs/"
2013/07/11 04:01:49 [error] 406#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 220.255.2.143, server: instaneous.pin.gs, request: "GET /socket.io/1/?t=1373515310157 HTTP/1.1", upstream: "http://127.0.0.1:3002/socket.io/1/?t=1373515310157", host: "instaneous.pin.gs", referrer: "http://instaneous.pin.gs/"
2013/07/11 04:01:50 [error] 406#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 220.255.2.143, server: instaneous.pin.gs, request: "GET /socket.io/1/?t=1373515311158 HTTP/1.1", upstream: "http://127.0.0.1:3002/socket.io/1/?t=1373515311158", host: "instaneous.pin.gs", referrer: "http://instaneous.pin.gs/"