I have created a Django application with channels. Now I am configuring it for production in AWS EC2. I can access the app when running the python manage.py runserver 0.0.0.0:8000
. The apps that I deployed to AWS were using wsgi only and need only Gunicorn. But since channels use asgi the Daphne was used. It specifies few steps in the docs (https://channels.readthedocs.io/en/latest/deploying.html)
/etc/supervisor/conf.d/asgi.conf
[fcgi-program:asgi]
# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8000
# Directory where your site's project files are located
directory=/home/ubuntu/myproject
# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=/home/ubuntu/venv/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers myproject.asgi:application
# Number of processes to startup, roughly the number of CPUs you have
numprocs=1
# Give each process a unique name so they can be told apart
process_name=asgi%(process_num)d
# Automatically start and recover processes
autostart=true
autorestart=true
# Choose where you want your log to go
stdout_logfile=/home/ubuntu/log/asgi.out.log
stderr_logfile=/home/ubuntu/log/asgi.err.log
redirect_stderr=true
/etc/nginx/sites-enabled/django.conf
upstream channels-backend {
server localhost:8000;
}
server {
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
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;
}
}
These were the configuration files added as mentioned in the docs. But the application is not live. What is the socket param in asgi.conf means? Is the channels-backend in the proxy_pass points to the upstream channels-backend? Can someone help me understanding these files and fixing the solution?
I found some tutorials on earlier versions of Channels. I this there the serve wsgi and asgi separately. But I think channels 3, It will handle both asgi and wsgi accordingly.