Deploying django, channels and websockets with nginx and daphne

Larry Martell larry.martell at gmail.com
Wed Feb 26 22:55:02 UTC 2020


I've posted this to the django mailing list and to stack overflow,
with no replies so trying here.

I am trying to deploy a django app that uses channels and websockets,
with nginx and daphne.

When I was using uwsgi, here was my nginx file:

upstream django {
        server unix:/run/uwsgi/devAppReporting.sock;
}

server {
        listen 8090;
        server_name foo.bar.com;
        charset utf-8;

        location /static {
                alias /var/dev-app-reporting/static;
        }

        location / {
               uwsgi_pass django;
               include /var/dev-app-reporting/uwsgi_params;
               uwsgi_read_timeout 3600;
               client_max_body_size 50m;
        }
}

Now I changed it to this:

upstream django {
        server unix:/run/daphne/devAppReporting.sock;
}

server {
        listen 8090;
        server_name foo.bar.com;
        charset utf-8;

        location /static {
                alias /var/dev-app-reporting/static;
        }

        location / {
            proxy_pass http://0.0.0.0:8090;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
}

Started daphne like this:

daphne -u /run/daphne/devAppReporting.sock app.dse.asgi:application

I get a 502 bad gateway error and this in the log:

2020/02/24 22:17:26 [alert] 29169#29169: 768 worker_connections are not enough
2020/02/24 22:17:26 [error] 29169#29169: *131545 recv() failed (104:
Connection reset by peer) while reading response header from upstream,
client: 127.0.0.1, server:
dse-portfolio-dev-assessments.md.virtualclarity.com, request: "GET /
HTTP/1.1", upstream: "http://0.0.0.0:8090/", host: "xx.xx.xx.xx"

Any ideas on what I should have in my config file for this to work?


More information about the nginx mailing list