I have my node app running on port 3000. Then I use nginx as a reverse proxy to serve the application with SSL of my domain :
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;
}
}
I initialize my socket in client-side with this line :
var socket = io.connect('https://example.com/');
And in servers-side with this line :
var io = socket_io()
app.io = io
But when I launch my application I have this error :
WebSocket connection to 'wss://example.com/socket.io/?EIO=3&transport=websocket&sid=jVNRhDOYJD20l9U-AAAA' failed: Error during WebSocket handshake: Unexpected response code: 502
Do you know how to fix this error ?
This article describes using nginx as a rev-proxy in front of the Kaazing WebSocket server.
https://kaazing.com/kaazing-and-nginx-the-best-of-both-worlds/
The config described in the article might be very similar to using NodeJS as the server. Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.