【问题标题】:Repeatedly getting message: You're accessing the development server over HTTPS, but it only supports HTTP反复收到消息:您正在通过HTTPS访问开发服务器,但它只支持HTTP
【发布时间】:2019-12-08 21:41:21
【问题描述】:

我正在尝试 Dockerize 我的 Django 应用程序。在我的 settings.py 中,如果DEBUG=True,我将所有安全设置都设置为 False。我在 settings.py 的底部专门打印了f"DEBUG={DEBUG}"f"SECURE_SSL_REDIRECT = {SECURE_SSL_REDIRECT}"。但我反复收到消息You're accessing the development server over HTTPS, but it only supports HTTP.。是什么赋予了?我已经看到some other questions 表明这个变量导致了问题,但对我来说似乎并非如此,因为它绝对设置为 False。

settings.py

# SITE SECURITY (security)
if DEBUG is False:
    CSRF_COOKIE_SECURE = True
    SECURE_CONTENT_TYPE_NOSNIFF = True
    SECURE_BROWSER_XSS_FILTER = True
    SESSION_COOKIE_SECURE = True
    X_FRAME_OPTIONS = 'DENY'
    SECURE_SSL_REDIRECT = True
    SECURE_HSTS_SECONDS = 17068000 # > 6 months (197 days)
    SECURE_HSTS_INCLUDE_SUBDOMAINS = True
    SECURE_HSTS_PRELOAD = True
else:
    CSRF_COOKIE_SECURE = False
    SECURE_CONTENT_TYPE_NOSNIFF = False
    SECURE_BROWSER_XSS_FILTER = False
    SESSION_COOKIE_SECURE = False
    SECURE_SSL_REDIRECT = False
    SECURE_HSTS_INCLUDE_SUBDOMAINS = False
    SECURE_HSTS_PRELOAD = False


print(f"SECURE_SSL_REDIRECT = {SECURE_SSL_REDIRECT}")

docker-compose up 输出

System check identified no issues (0 silenced).
web_1  | December 08, 2019 - 21:32:49
web_1  | Django version 2.1.1, using settings 'my_app.settings'
web_1  | Starting development server at http://0.0.0.0:8000/
web_1  | Quit the server with CONTROL-C.
web_1  | "True"
web_1  | DEBUG=True
web_1  | SECURE_SSL_REDIRECT = False
web_1  | Performing system checks...
web_1  |
web_1  | System check identified no issues (0 silenced).
web_1  | December 08, 2019 - 21:32:59
web_1  | Django version 2.1.1, using settings 'my_app.settings'
web_1  | Starting development server at http://0.0.0.0:8000/
web_1  | Quit the server with CONTROL-C.
web_1  | [08/Dec/2019 21:33:07] code 400, message Bad request syntax ("\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x1dn\xe4j\xdc8~\x02\xc2\x04\x89\xdd\x005^\xba\x9a\xa7\xa3xt\xc4.\xef,\xf7\x06\xedsOa\x81 \x87/E\xc9\xc1Hn\xe0%'\x93\xf4\t\xbd\xcb9")
web_1  | [08/Dec/2019 21:33:07] You're accessing the development server over HTTPS, but it only supports HTTP.

【问题讨论】:

  • 尝试清除浏览器缓存
  • 好建议,但不幸的是,清空缓存和硬重新加载并不能解决问题。
  • 您是否尝试过其他浏览器?
  • 哇。火狐工作。谢谢!

标签: python django docker docker-compose


【解决方案1】:

您的服务器不支持 https,因此请设置以下设置:

SECURE_SSL_REDIRECT=False
SESSION_COOKIE_SECURE=False
CSRF_COOKIE_SECURE=False

或者它可能是您在 chrome 上的浏览​​器的问题,转到设置 > 隐私和安全 > 清除浏览历史记录并将时间范围设置为所有时间,然后清除您的数据。这对我有用。

【讨论】:

  • 看起来这些设置已经在问题的 settings.py 的else 分支中设置了。
猜你喜欢
  • 2016-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-09
  • 2018-01-19
  • 2017-09-02
  • 2020-03-08
  • 1970-01-01
相关资源
最近更新 更多