2

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?

Larry Martell
  • 3,526
  • 6
  • 40
  • 76
  • you might need to proxy pass the other websocket handshake headers.see `Client handshake request` https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers – Matthaus Woolard Feb 25 '20 at 22:56

1 Answers1

0

I got this working. The fix was to change the proxy_pass line to:

proxy_pass http://django;
Larry Martell
  • 3,526
  • 6
  • 40
  • 76