django的Secure_ssl_redirect设置对heroku没有任何作用 [英] Secure_ssl_redirect setting for django does nothing on heroku

查看:251
本文介绍了django的Secure_ssl_redirect设置对heroku没有任何作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在heroku上部署一个Django应用程序,并尝试在所有页面上强制 https 。我使用以下设置:

I am deploying a Django app on heroku and trying to force https on all pages. I use the following settings for that:

SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

现在我访问www.mysite .de它确实没有将我重定向到https。我缺少什么想法?

Now when I visit www.mysite.de it does in fact not redirect me to https. Any ideas what I am missing?

推荐答案

尝试将以下内容添加到settings.py:

Try adding the following to your settings.py:

PREPEND_WWW = True
BASE_URL = "https://www.mysite.de"
ALLOWED_HOSTS = ['www.mysite.de', 'mysite.de']

确保你还有 SecurityMiddleware CommonMiddleware 已启用。

这篇关于django的Secure_ssl_redirect设置对heroku没有任何作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆