Question

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

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 { ip_hash; server $DAPHNE_IP_ADDRESS$ fail_timeout=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;
}

}

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This comment has been deleted

Im running the same issue, could you find any solution in this? Thabk you

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