Django Channels Nginx Supervisor deployment configuration

Published 26 Jan, 2023

Reading time: 2 Mins

How to properly deploy Django Daphne server to supervisor and Nginx?

I deployed project to VPS and it took some time to figure out the problem during the deployment. However I putting the configuration files here and you can use this to ease your deployment.

cat /etc/supervisor/conf.d/blogstreak.conf

# TCP socket used by Nginx backend upstream

# Directory where your site's project files are located

# 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/rajasimon/blogstreak/venv/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers blogstreak.asgi:application

# Number of processes to startup, roughly the number of CPUs you have

# Give each process a unique name so they can be told apart

# Automatically start and recover processes

# Choose where you want your log to go
upstream channels-backend {
    server localhost:8000;

server {
    #if ($host = {
        #return 301 https://$host$request_uri;
    listen 80;
    listen [::]:80;

server {
    #listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
        include proxy_params;
        proxy_pass http://channels-backend;

    location /ws {
        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;

Change server_name to your domain and restart the nginx and supervisor

Read More