2013-05-19 2 views
0

node.js가 nginx 뒤에있는 socket.io를 설정했습니다. 메인 도메인이 nginx에서 실행 중이고 서브 도메인이 node.js로 프록시되고 있습니다. 모든 REST API는 정상적으로 작동하지만 소켓 연결과 관련하여 로그에서 핸드 셰이크를 볼 수는 있지만 클라이언트는 분명히 응답을 얻을 수 없습니다. 아래는 node.js의 로그이며, 아래에 제가 사용하고있는 설정이 있습니다. 어떤 아이디어가 효과가 없는지?node.js와 nginx를 사용하여 socket.io에 연결할 수 없습니다.

info - handshake authorized 7WtMDKRY1tPb97CORlJ4 
debug - setting request GET /socket.io/1/websocket/7WtMDKRY1tPb97CORlJ4 
debug - set heartbeat interval for client 7WtMDKRY1tPb97CORlJ4 
debug - client authorized for 
debug - websocket writing 1:: 
debug - clearing poll timeout 
debug - jsonppolling writing io.j[0]("8::"); 
debug - set close timeout for client JoDWOVTvLg7SdYpNRlJ2 
debug - jsonppolling closed due to exceeded duration 
debug - setting request GET /socket.io/1/xhr-polling/7WtMDKRY1tPb97CORlJ4?t=1368925686996 
debug - setting poll timeout 
debug - discarding transport 
debug - cleared heartbeat interval for client 7WtMDKRY1tPb97CORlJ4 
debug - setting request GET /socket.io/1/jsonp-polling/7WtMDKRY1tPb97CORlJ4?t=1368925696997&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 7WtMDKRY1tPb97CORlJ4 
debug - jsonppolling closed due to exceeded duration 
debug - setting request GET /socket.io/1/jsonp-polling/7WtMDKRY1tPb97CORlJ4?t=1368925717060&i=0 
debug - setting poll timeout 
debug - discarding transport 
debug - cleared close timeout for client 7WtMDKRY1tPb97CORlJ4 
debug - clearing poll timeout 
debug - jsonppolling writing io.j[0]("8::"); 
debug - set close timeout for client 7WtMDKRY1tPb97CORlJ4 
debug - jsonppolling closed due to exceeded duration 
debug - setting request GET /socket.io/1/jsonp-polling/7WtMDKRY1tPb97CORlJ4?t=1368925737199&i=0 
debug - setting poll timeout 
debug - discarding transport 
debug - cleared close timeout for client 7WtMDKRY1tPb97CORlJ4 
debug - fired close timeout for client JoDWOVTvLg7SdYpNRlJ2 
info - transport end (close timeout) 

의 Nginx의 설정 :

upstream app_yourdomain { 
    server 127.0.0.1:3000; 
} 

# the nginx server instance 
server { 
    listen 80; 
    server_name mydomain.com; 

    # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options 
    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_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection "upgrade"; 

     tcp_nodelay on; 
     proxy_pass http://app_yourdomain/; 
     proxy_redirect off; 
    } 
} 

Socket.io는 127.0.0.1:3000에서 실행됩니다.

답변

2

충분히 새로운 버전의 nginx를 실행하고 있습니까? WebSocket 지원은 nginx 버전 1.3.13에서 소개되었습니다. nginx -v을 사용하여 보유하고있는 버전을 확인하십시오. 또한 https://chrislea.com/2013/02/23/proxying-websockets-with-nginx/

+0

나는 최근에'apt-get'을 통해 설치했고 최근에 전체 시스템을 업그레이드했지만 1.1.19 만 실행 중이다. 나는 지금 그것을 업그레이드하려고 노력할 것이다. – Sherzod

+0

1.4.1로 업그레이드되었으며 현재 정상적으로 작동 중입니다. 감사! – Sherzod

+0

클라이언트 쪽에서 소켓을 연결하고 있는데 코드에서 액세스하는 방법은 var socket = io.connect ('/ explorer/socket', { 'reconnect': true, ' 지연 ': 500 }); –

관련 문제