By yaku buku
I’m running a Django Channels app on DigitalOcean, Ubuntu 16.04 using Daphne and Nginx. I’m trying to make this as simple as possible right now, I just want to be able to go to my domain name and see my app being served.
Followed this post.
“Nginx will only be used as a proxy for your django application, your django application will be running with daphne. And you should have daphne running on 127.0.0.1:8001 (or change the port to your likings).”
I have enabled Let’s Encrypt SSL for my page and told all http requests to be redirected to https.
My page is showing the error
myapp.com redirected you too many times.
I’m running daphne on 127.0.0.1:8001.
daphne -b 127.0.0.1 -p 8001 myapp.asgi:application
I can see the app on my VPM droplet’s ip address if I run the below command, but obviously I want to see the app on myapp.com, not the IP address!
daphne -b 44.444.444.444 -p 8001 myapp.asgi:application
my nginx config file
server {
listen 80;
server_name myapp.com www.myapp.com;
server_tokens off;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl; # managed by Certbot
server_name myapp.com www.myapp.com;
ssl_certificate /etc/letsencrypt/live/myapp.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myapp.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
root /home/me/myapp/src/myapp;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/me/myapp/src/myapp;
}
location /media/ {
root /home/me/myapp/src/myapp;
}
location / {
try_files $uri $uri/ @python_django;
}
location @python_django {
proxy_pass http://127.0.0.1:8001;
proxy_pass_request_headers on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
}
I’ve spent weeks trying to get this to work and obviously need help. I’ve looked through the docs and
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!
Greetings!
I invite anyone else to weigh in on this who may have more experience with Django and Daphne, but I wanted to weigh in what I do know about this error you are receiving.
The error in itself simply means that the website is redirecting to itself in a loop. If Nginx is redirecting requests to https, then I might propose that the back-end application is redirecting requests to http. This is not at all uncommon, many back-end applications enforce their site URL as configured in their code, and reversing http/https redirects on both ends will cause this.
It would then be my suggestion to take a look at how the back-end app works, and see if this is something you can influence in it’s behavior.
Jarland
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.