Socket.io不Nginx的反向代理工作中的Node.js
问题描述:
前我有我的节点的应用程序运行在端口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
你知道如何解决这个问题?
答
本文介绍如何在Kaazing WebSocket服务器前使用nginx作为rev-proxy。
https://kaazing.com/kaazing-and-nginx-the-best-of-both-worlds/
文章中所描述的配置可能会非常类似于使用作为的NodeJS服务器。希望能帮助到你。