Ngninx not working with Socket.io and ssl

November 3, 2019 92 views
Nginx

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!

Be the first one to answer this question.