我已经在 digitalocean 上设置了一个 django 应用程序,并且使用了最少的 nginx 和 Gunicorn 设置。我使用 cloudflare 管理我的 dns,还使用 cloudflare 的灵活 ssl。现在的问题是我的所有 django 生成的 url 都有 http url( http://example.com/favicon.ico ),如何使所有 url 都为 https?
Nginx session :
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;
}
}
最佳答案
Django确实提供了SECURE_SSL_REDIRECT将所有网址重定向到 https 的设置,
将其添加到您的 settings.py 文件中
if not DEBUG:
SECURE_SSL_REDIRECT = True
此外,请查看 SSL 实现指南 here .
关于python - Django 所有 url SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45790753/