Hey Miguel, I really hate to bother you again but I'm stumped. I just deployed my app to an nginx server and am running socketio with gunicorn/gevent. When I manually run gunicorn with gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --bind 0.0.0.0:5000 wsgi:app
everything runs fine on port 5000 with no errors.
However, when I instead start the full service with gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --bind unix:app.sock -m 007 wsgi:app
I get this error in the browser console: WebSocket connection to 'ws://xxx.xxx.xxx.xxx/socket.io/?EIO=3&transport=websocket&sid=4e2ee52aefd54090981e2d7353114449' failed: Error during WebSocket handshake: Unexpected response code: 200.
I figured the problem might be with the connection not being upgraded, so I added this to my sites-enabled file:
location /socket.io {
proxy_http_version 1.1;
proxy_redirect off; proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade";
}
But then the console starts spitting out
GET http://xxx.xxx.xxx.xxx/socket.io/?EIO=3&transport=polling&t=LnNHzH-404 (Not Found) every time the socket tries to connect. Any ideas where the problem might be?
It seems you are missing the upstream node(s) in your configuration.. See this example config, that is a config file that I'm currently using.
Thanks for the quick reply. I have the upstream nodes in my config, but you are right I was missing them from /socket.io. That fixed the 404, but now I'm just getting bad gateways. Do I need to pass the nodes proxy into the / location? I am already using it to serve my main socket.
upstream nodes {
ip_hash;
server 127.0.0.1:5000;
}
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
location / {
include proxy_params;
proxy_pass http://unix:/home/me/website/website.sock;
}
location /socket.io {
proxy_pass http://nodes/socket.io;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
The 502 error usually means that the service isn't running, or at least it isn't running in the IP address and port configured in nginx. Check that you can contact your server at localhost:5000, the error seems to indicate it isn't available.
You literally just started my website. Thank you for all of your help, you have really been incredibly patient, more so than I could ask for. It's pretty clear this is my first webapp and hopefully this means I can now stop pestering you. Thanks again!