Serving Django Channels app w/ Nginx and Daphne throws 403 Forbidden error

March 7, 2019 2.5k views
Ubuntu 16.04 Nginx Django

I’m serving my Django Channels app using only Daphne (ASGI) and Nginx as a proxy for my Django app to begin with.

Daphne is running on 127.0.0.1:8001.

However, I am running into a 403 Forbidden error.

2019/03/06 17:45:40 [error] *1 directory index of "/home/user1/app/src/app/" is forbidden

Would someone mind looking over my code as I can’t seem to solve this.

upstream socket {
iphash;
server $DAPHNE
IPADDRESS$ failtimeout=0;
}

server {

listen 80;
#listen [::]:80 ipv6only=on;

server_name your.server.com;
access_log /etc/nginx/access.log;

root /var/www/html/someroot;

location / {
        #autoindex on;

        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        # try_files $uri =404;

        #proxy_set_header X-Real-IP $remote_addr;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_set_header Host $http_host;
        #proxy_set_header X-NginX-Proxy true;
        #proxy_pass http://socket;
        #proxy_redirect off;
        #proxy_http_version 1.1;
        #proxy_set_header Upgrade $http_upgrade;
        #proxy_set_header Connection "upgrade";

        #proxy_redirect off;
        #proxy_set_header   X-Forwarded-Proto $scheme;
        #proxy_cache one;
        #proxy_cache_key sfs$request_uri$scheme;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/some/fullchain.pem;
# managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/some/privkey.pem; 
# managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

if ($scheme != "https") {
    return 301 https://$host$request_uri;
}

}

2 comments
1 Answer

Greetings!

Someone with more experience in this setup may also want to weigh in, but I wanted to offer my thoughts.

I would check the user that Daphne is running under, and then run something like this:

chown -R user. /home/user1/app/src/app

Replacing “user” with that of the user running Daphne.

Jarland

Have another answer? Share your knowledge.