nginx 取消 https 后发现 chrome 访问提示重定向过多无法访问。

2016-12-14 19:29:15 +08:00
 smallaccount
取消了https rewrite 到了http,但是发现 chrome 访问提示重定向过多无法访问。
自己可以清楚 cookie 解决,但是用户怎么办啊。
或者是我哪里设置有问题?
比如说,如何告诉浏览器我修改了nginx的配置文件?
12224 次点击
所在节点    NGINX
36 条回复
loveyu
2016-12-14 22:33:32 +08:00
lslqtz
2016-12-14 22:35:58 +08:00
lslqtz
2016-12-14 22:37:43 +08:00
顺便向各位道个歉:我说配置有问题可能太果断,但以后可以在跳转的域名中加入以下指令:
add_header Cache-Control no-cache
smallaccount
2016-12-14 22:42:21 +08:00
@loveyu http 的话直接显示网页内容了, https 的话和上面的那个一样。。。
loveyu
2016-12-14 22:54:43 +08:00
@smallaccount 我指这类数据
curl -I http://www.v2ex.com
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.11.6
Date: Wed, 14 Dec 2016 14:54:04 GMT
Content-Type: text/html
Content-Length: 161
Connection: keep-alive
Location: https://www.v2ex.com/
X-ORCA-Accelerator: from 093.chn.fuo01.cn.krill.c3edge.net
smallaccount
2016-12-15 10:09:11 +08:00
@flynaj

@loveyu 纯小白,刚才写成 curl -l 了,应该是 curl -I.

http
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 14 Dec 2016 14:46:53 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 7996
Connection: keep-alive
Cache-Control: no-cache

https
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 14 Dec 2016 14:48:01 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://www.domain.com/

重新设置为 302 了,目前依旧无法正常访问。

@lslqtz 方法没用,加了,加在 proxy_set_header X-Real-IP $remote_addr;下面了,还不行。。。

目前设置:
server {
listen 80;
server_name domain.com www.domain.com;
if ($host != 'www.domain.com')
{
rewrite ^/(.*)$ http://www.domain.com/$1 redirect;
}
proxy_cache_valid 301 1m;
location / {
proxy_pass http://127.0.0.1:8000/;
limit_req zone=one burst=20 nodelay;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
add_header Cache-Control no-cache;
}
location /static {
alias /var/www/domain/static;
}
}
server {
listen 443 ssl;
server_name domain.com www.domain.com;
proxy_cache_valid 301 1m;

rewrite ^/(.*)$ http://www.domain.com/$1 redirect;

ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
}
smallaccount
2016-12-15 10:16:37 +08:00
@raysonx 我觉得你说的最靠谱,主要是 chrome 缓存了 301 的问题,但是怎么清楚客户端 chrome 的 301 缓存呢?
figofuture
2016-12-15 10:36:55 +08:00
这篇帖子有回答 https://www.v2ex.com/t/314217
lslqtz
2016-12-15 11:38:32 +08:00
@smallaccount 我觉得没什么办法。
因为 https 到 http 缓存了, http 到 https 又缓存了。
给你的配置是避免以后出问题的。。
smallaccount
2016-12-15 18:23:55 +08:00
@figofuture 问题和我一样,很多人都答非所为,目测没有题主解决。
allenhu
2016-12-16 07:39:43 +08:00
hsts 设置了 Strict-Transport-Security: max-age 吧
lslqtz
2016-12-16 09:35:00 +08:00
@allenhu 我觉得这样还是没法解决 https 跳转到 http
lslqtz
2016-12-16 09:35:36 +08:00
@smallaccount 我建议通知客户手动清除,下次加 no-cache 。。
smallaccount
2016-12-16 10:00:32 +08:00
@allenhu 非非非常感谢!!!
纯小白什么也不懂,我是按照 digitalocean 上给的教程配置的
https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04

然后这个教程设置了 Strict-Transport-Security: max-age ,所以导致了上述的情况, http 直接无法访问,全部都跳转到 https 了,取消设置之后 http 和 https 都可以访问了。 digitalocean 设置的是 15768000 , 182.5 天。。。好吧,只能等用户自己清除了,我这边先把 https 加上去好了,等到半年后再把 https 撤下来,估计差不多。。


@lslqtz chrome 客户端缓存可能是无法解决了,但是终于知道原因了。
lslqtz
2016-12-16 11:51:38 +08:00
@smallaccount chrome://net-internals/#hsts
这里可以清理,只要没有加入列表。
我以为你是普通的 301 。。没想到你开了 HSTS
smallaccount
2016-12-16 12:15:29 +08:00
@lslqtz 的确应该把配置 https 和取消 https 之后的两个配置文件都贴上去的。。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/327678

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX