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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With