2

I have setup a django application on digitalocean with minimal nginx and gunicorn setup. I am managing my dns using cloudflare and also using cloudflare's flexible ssl. Now the problem is all of my django generated urls have http url(http://example.com/favicon.ico), how can I make all url https?

Nginx Conf:

server {
listen       80;
client_max_body_size 4G;
server_name  ***;

location / {
    include proxy_params;
    proxy_pass http://unix:**.sock;
}
location /static {
    autoindex off;
    alias **/static_files;
}

location /media {
    autoindex off;
    alias **/media;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}
}
Minuddin Ahmed Rana
  • 1,084
  • 1
  • 15
  • 27
  • See related - https://stackoverflow.com/questions/26435272/how-to-use-django-sslify-to-force-https-on-my-djangonginxgunicorn-web-app-and?rq=1 – shad0w_wa1k3r Aug 21 '17 at 06:47

1 Answers1

2

Django does provide SECURE_SSL_REDIRECT setting for redirecting all urls to https,

Add this on your settings.py file

if not DEBUG:
    SECURE_SSL_REDIRECT = True

Also , have a look at the guidelines for SSL implementation here.

Aniket Pawar
  • 2,641
  • 19
  • 32
  • It throws 'ERR_TOO_MANY_REDIRECTS' – Minuddin Ahmed Rana Aug 21 '17 at 06:53
  • can you update your question and show the nginx configuration ? – Aniket Pawar Aug 21 '17 at 06:59
  • Since your question is about redirecting all request to https in django, this setting should work but as you haven't configured the SSL in nginx. I suggest you to just have a look at one of the tutorials.Minimal setup can be found [here](https://simpleisbetterthancomplex.com/tutorial/2016/05/11/how-to-setup-ssl-certificate-on-nginx-for-django-application.html) – Aniket Pawar Aug 21 '17 at 07:38
  • I am using cloud flare flexible ssl which is work like this(https://i.stack.imgur.com/6qY4H.png). I need to make all system generated url to https – Minuddin Ahmed Rana Aug 21 '17 at 08:15