2015-12-14 65 views
0

前我有我的節點的應用程序運行在端口3000 然後我使用nginx的反向代理與我的域名的SSL服務應用程序:Socket.io不Nginx的反向代理工作中的Node.js

server { 
     listen 443 ssl; 

     ssl_certificate /etc/nginx/ssl/server.chain.crt; 
     ssl_certificate_key /etc/nginx/ssl/server.key; 

     server_name example.com; 

     location/{ 
       proxy_pass http://localhost:3000; 
       proxy_http_version 1.1; 
       proxy_set_header Upgrade $http_upgrade; 
       proxy_set_header Connection 'upgrade'; 
       proxy_set_header Host $host; 
       proxy_cache_bypass $http_upgrade; 
    } 
} 

我初始化我在客戶端套接字這一行:

var socket = io.connect('https://example.com/');

而在服務器端使用此行:

var io = socket_io() 
app.io = io 

但是,當我啓動我的應用我有這個錯誤:

WebSocket connection to 'wss://example.com/socket.io/?EIO=3&transport=websocket&sid=jVNRhDOYJD20l9U-AAAA' failed: Error during WebSocket handshake: Unexpected response code: 502

你知道如何解決這個問題?

回答