Socket.io nginx configuration Error during WebSocket handshake: "Connection" header value is not "Upgrade": keep-alive

I got an error when running socket.io on nginx (nginx / 1.1.19) on my server

WebSocket handshake error: "Connection" header value is not "Update": keep-alive

My conf file for my site:

server{ listen 80; server_name lalala.com; access_log /home/hao/sites/reactjsweekly/accesss.log; error_log /home/hao/sites/reactjsweekly/error.log; 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_pass http://127.0.0.1:3002/; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } 

socket.io server side:

 var server = http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); }); var io = require('socket.io').listen(server); io.sockets.on('connection', function (socket) { socket.emit('info', {data: "lala"}); }); }); 

Has anyone encountered the same problem before ???

+8
nginx sockets
source share
2 answers

[1] "Starting with version 1.3.13, nginx implements a special mode of operation that allows you to configure the tunnel between the client and the proxy server if the proxy server returned a response with code 101 (Switching Protocols), and the client asked the protocol switch through the heading" Update "in request."

Your version 1.1.19; update and should work as expected.

+1
source share

Several implementation checks for Upgrade <<are capitalized.

proxy_set_header Connection "upgrade";

must be uppercase

proxy_set_header Connection "upgrade";

0
source share

All Articles