V2EX 是怎样做 http 转 https 的?

2014 年 11 月 18 日
 iugo
http://blog.csdn.net/wzy_1988/article/details/8549290 这里看到大概有三种方法:

1. rewrite
2. 497 状态码 (似乎不太友好)
3. 进入页面后跳转 (似乎这样相当于加载了两次)

想知道 V2EX 是怎样做的?

另:
页面中还有 <link rel="canonical" href="https://study.congcong.us/" /> 这个需要改成 https 吗? 我的 Ghost 也是这样, 强制了 https, 但 canonical 还是 http. 有必要改吗?
4318 次点击
所在节点    V2EX
14 条回复
leassy
2014 年 11 月 18 日
80端口直接301到443端口即可
我一直这样做
tabris17
2014 年 11 月 18 日
永久重定向
iugo
2014 年 11 月 18 日
@leassy
@tabris17

具体该怎么做?

我是这样的:

server {
listen 80;
server_name example.org;
return 301 https://example.org$request_uri;
}

可是之后出现了一个问题, 百度站内搜索失效. 之前还是警告页面包含非加密信息, 后来就直接失效了, 虽然也不会有提醒. 注: znsv.baidu.com 无法使用 https.
tabris17
2014 年 11 月 18 日
原链接失效搜索引擎当然也失效了。

包含非加密信息是因为你引用图片脚本CSS使用了绝对地址吧
iugo
2014 年 11 月 18 日
知道问题在哪儿了. 是 Chrome 屏蔽了该不安全脚本.
iugo
2014 年 11 月 18 日
@tabris17 我引用的是百度

<script type="text/javascript">document.write(unescape('%3Cdiv id="bdcs"%3E%3C/div%3E%3Cscript charset="utf-8" src="http://znsv.baidu.com/customer_search/api/js?sid=4316253844246803945') + '&plate_url=' + (encodeURIComponent(window.location.href)) + '&t=' + (Math.ceil(new Date()/3600000)) + unescape('"%3E%3C/script%3E'));</script>

这样一行代码.

刚开始测试的时候还正常显示, 后来被 Chrome 屏蔽了, 选择加载不安全代码后就正常了.

虽然听说百度开始支持 https 了, 但 znsv.baidu.com 还是不支持.
kslr
2014 年 11 月 18 日
497
Showfom
2014 年 11 月 18 日
v2ex 从来没有强制 https 啊 做跳转是因为你在自己的设置里设置了 那当然应该是用 python 判断咯
cokebar
2014 年 11 月 18 日
页面引用时候可以用省略了协议的url:
//www.example.com/index.html
这样根据情况浏览器会相应处理
xoxo
2014 年 11 月 18 日
将80重定向到443同时
输出如下http header
Strict-Transport-Security:max-age=31536000; includeSubDomains
leassy
2014 年 11 月 19 日
@iugo
server {
listen 80;
server_name xxx.com;
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
leassy
2014 年 11 月 19 日
@iugo 刚才少了个括号
server {
listen 80;
server_name w9z.net;
rewrite ^/(.*)$ http://www.w9z.net/$1 permanent;
}
iugo
2014 年 11 月 19 日
@kslr 497 有什么好处呢?
iugo
2014 年 11 月 19 日
@Showfom 嗯. 我在 Chrome 和 Firefox 看到是自动跳 https. 刚才又在 IE 11 中测试, 没有跳, 依旧是 http.

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

https://study.congcong.us/t/147521

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

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

© 2021 V2EX