gpt4 book ai didi

django LOGIN_REDIRECT_URL 在 nginx ssl 后面不工作

转载 作者:太空宇宙 更新时间:2023-11-03 14:15:53 27 4
gpt4 key购买 nike

站点的其余部分可以正常工作,但登录后的重定向是

http ://127.0.0.1:8443/after_login

不是预期的

https://127.0.0.1:8443/after_login

这会导致 nginx 错误:

400 错误请求普通 HTTP 请求被发送到 HTTPS 端口

如何强制正确构建重定向链接?

环境信息:

Django 1.4.1

设置.py

LOGIN_REDIRECT_URL = reverse_lazy('after_login')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')

最佳答案

在我将 proxy_set_header X-Forwarded-Proto $scheme 添加到 nginx 的配置之前,它一直发生在我身上:

location / {
proxy_pass http://unix:/path/to/your/gunicorn_socket;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

关于django LOGIN_REDIRECT_URL 在 nginx ssl 后面不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20124891/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com