Wednesday 17 May 2017

Socket.io not working with nginx

I have a nicely working django website which is being served by gunicorn and nginx(as a proxy server), now i want to add chat mechanism in that website using socket.io and nodejs. The problem is that the chat works perfectly fine when i connect socketio directly to nodejs server(which is listening on port 5000) but when i try to use nginx to proxy the socketio request to nodejs it doesn't work.

Here is my nginx file in /sites-enabled/ dir

server {
    listen 80;
    server_name 127.0.0.1;

    location = /favicon.ico {
        access_log off;
        log_not_found off;
    }
    location /static/ {
        root /path/to/static;
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/path/to/file.sock;
    }

    location /socket.io/ {
        proxy_pass http://127.0.0.1:5000;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}



via user6908290

No comments:

Post a Comment