【发布时间】:2015-12-14 20:31:15
【问题描述】:
我的节点应用程序在端口 3000 上运行。 然后我使用 nginx 作为反向代理,通过我的域的 SSL 为应用程序提供服务:
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
你知道如何解决这个错误吗?
【问题讨论】:
标签: node.js nginx websocket socket.io