Search code examples
pythondjangonginxdjango-socketio

Socket.IO with Django, Nginx and Gunicorn


I'm trying to set up a Django server with Socket.io running. I've looked all over the place and tried a million different things but I can't figure out how to get nginx and gunicorn to play nice with django-socketio. Can anyone help? Specifically, is there a tutorial anyone can point me to that they have successfully gotten to work? Thanks!


Solution

  • The trick is to have a nginx block that catches socket.io frames and forwards them to your the django-socketio server. Assuming thats running on port 9000, try:

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

    A good tutorial can also be found here .