Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django channels daphne returns 200 status code

I have setup a Django application with Nginx + uwsgi. The application also uses django-channels with redis. When deploying the setup in an individual machine, everything works fine.

But when I tried to setup the app in 2 instances and setup a common load balancer to coordinate the requests, the request get properly routed to the daphne process and I can see the logs. But the status code returned from the daphne process is 200 instead of 101.

Load balancer nginx conf:

upstream webservers {
    server 10.1.1.2;
    server 10.1.1.3;
}


server {
    location / {
        proxy_pass http://webservers;
    }
}

Versions used:

daphne==2.2.4
channels==2.1.6
channels-redis==2.3.2

All the routing works fine and there are no errors, but just that the status code returned is 200 instead of 101.

like image 885
Aswin Murugesh Avatar asked Oct 16 '22 11:10

Aswin Murugesh


1 Answers

Try to add following headers, hope that this will help:


server {
    location / {
        proxy_pass http://webservers;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
   }
}

Full official instruction about how to setup Django Channels + Nginx can be found here

like image 56
wowkin2 Avatar answered Oct 22 '22 22:10

wowkin2