nginx - nginx 页面重定向不正确,如何解决?
问题描述
我的 nginx conf,目标是让所有的东西都不是 https 到 https,从 www 到不是 www,通过几个教程,我一直得到这个
页面未正确重定向
连接到 example.com 期间发生错误。
此问题有时可能是由禁用或拒绝接受 cookie 引起的。
.
server {
listen 80;
server_name "~^www\.(.*)$" ;
return 301 https://example.com$request_uri ;
}
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate pathto/fullchain.pem;
ssl_certificate_key pathto/privkey.pem;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl on;
ssl_certificate pathto/fullchain.pem;
ssl_certificate_key pathto/privkey.pem;
ssl_trusted_certificate pathto/chain.pem;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Frame-Options "SAMEORIGIN";
client_max_body_size 4G;
location /static/ {
alias /asd/ads/static/;
}
location /media/ {
alias /asd/ads/media/;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
}
看起来您的帖子主要是代码;请添加更多细节。
解决方案
我从我的 django 设置中删除
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
它工作!
推荐阅读
- ios - React Native 区分 iPhone 11 Pro 和 iPhone 12 Mini
- python - Kivy touch 是独家的
- raspberry-pi - 使用 fifo 和 pylsl 通过 wifi 从 RPi(raspberrypi 零 w)流式传输数据
- ssl - 无法将 HAProxy 实现为 HTTPS 的正向代理
- python-3.x - 无头 Chrome 不加载某些网页
- ssl-certificate - 如何使用 SAN 属性检查 SSL 证书到期日期
- javascript - 为什么 jumbotron(bootstrap) 的大小在变化?
- asp.net - 在 GenericRepository 中创建方法以按值获取数据库
- flutter-provider - 为什么安装provider包成功后,我的flutter项目还是无法导入provider/provider.dart包?
- c++ - 如何在 graphics.h 中进行 z 缓冲