Django所有网址SSL

时间:2017-08-21 06:43:38

标签: python django django-rest-framework

我在digitalocean上设置了一个django应用程序,只需要最少的nginx和gunicorn设置。我正在使用cloudflare管理我的dns,还使用cloudflare灵活的ssl。现在问题是我所有的django生成的网址都有http网址(http://example.com/favicon.ico),我该如何制作所有网址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;
}
}

1 个答案:

答案 0 :(得分:2)

Django确实提供了SECURE_SSL_REDIRECT设置,用于将所有网址重定向到https,

在settings.py文件中添加

if not DEBUG:
    SECURE_SSL_REDIRECT = True

另外,请查看SSL实施指南here