I have been trying to get nginx to play well with socket.io and my ssl configuration for a while. I can get to my site perfectly fine (over https) and everything functions properly except for the socket.io communication and when I open the debugging console I don’t see any WS available or running. My config file is like this:
server {
listen [::]:80;
listen 80;
server_name www.mywebsite.com;
access_log /var/log/nginx/access.log;
proxy_set_header X-Forwarded-Proto $scheme;
if ( $http_x_forwarded_proto != 'https' ) {
return 301 https://$host$request_uri;
}
location / {
proxy_pass http://127.0.0.1:8000;
include proxy_params;
}
location /socket.io/ {
include proxy_params;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:8000/socket.io/;
}
}
and my app is running with flask/gunicorn:
gunicorn --timeout=300 -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 app:app
Any help would be greatly appreciated!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hello, @ecda909
May I ask if you have checked our tutorial on how to server flash applications with gunicorn and Nginx:
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
If you’re not running Ubuntu 18.04 you can choose a different distro from here: https://www.digitalocean.com/community/tutorial_collections/83
Hope this helps. Let me know how it goes.
Regards, Alex