https
越来越普及,但是当用户自己访问 http
是控制不了的,所以强制跳转的功能就必不可少了,下面是几种强制跳转的方法
return 301
返回 301 错误,并跳转到 https 地址
1 | server { |
rewrite
1 | rewrite ^(.*)$ https://$host$1 permanent; |
两者相比,301 的方式在搜索引擎速度上要块一些。
error_page 497
1 | error code 497: normal request was sent to HTTPS |
在一个站点只允许 https 访问时, 如果使用 http 访问会报出497错误码
1 | error_page 497 https://$host$uri?$args; |
index.html refresh
百度页面 http://baidu.com 自动跳转 http://www.baidu.com 是灵活利用了 meta 的刷新属性
1 | > $ curl http://baidu.com |
原文链接: http://yoursite.com/2019/02/12/Nginx-http-强制跳转-https-地址/
版权声明: 转载请注明出处.