I have been on this for a month now without a working solution. Everything works fine in production but I have been trying to deploy my django-channels application using nginx as reverse proxy, supervisor to keep servers running, gunicorn to serve http requests and I am stuck at the weboscket request part using daphne to process http requests.
I am bindig with unix sockets: gunicorn.sock and daphne.sockThe Console returns:
WebSocket connection to 'ws://theminglemarket.com/ws/chat/undefined/' failed: Error during WebSocket handshake: Unexpected response code: 500
My supervisor config:
directory=/home/path/to/srccommand=/home/path/to/venv/bin/gunicorn_startuser=rootautostart=trueautorestart=trueredirect_stderr=truestdout_logfile=/path/to/log/gunicorn/gunicorn-error.log[program:serverinterface]directory=/home/path/to/srccommand=/home/path/to/venv/bin/daphne -u /var/run/daphne.sock chat.asgi:applicationautostart=trueautorestart=truestopasgroup=trueuser=rootstdout_logfile = /path/to/log/gunicorn/daphne-error.log
Redis server is up and Running, Sure of that, using redis-servermy nginx configurations:
upstream channels-backend {# server 0.0.0.0:8001; server unix:/var/run/daphne.sock fail_timeout=0;}upstream app_server { server unix:/var/run/gunicorn.sock fail_timeout=0;}server { listen 80; listen [::]:80; server_name theminglemarket.com www.theminglemarket.com; keepalive_timeout 5; client_max_body_size 4G; access_log /home/path/to/logs/nginx-access.log; error_log /home/path/to/logs/nginx-error.log; location /static/ { alias /home/path/to/src/static/; # try_files $uri $uri/ =404; } location / { try_files $uri @proxy_to_app; } location /ws/ { try_files $uri @proxy_to_ws; } location @proxy_to_ws { proxy_pass http://channels-backend; 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; } location @proxy_to_app { proxy_pass http://app_server; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; # we don't want nginx trying to do something clever with # redirects, we set the Host: header above already. proxy_redirect off; }}
Please ask for any other thing needed, I'll update as quickly as I can. Thank You.It's a chatting application, do you think I should use only Daphne, I'm considering the scalability, and that's why I used gunicorn to serve http requests. Hosting on Ubuntu Server