博客启用https(支持hexo)
- CloudFlare是目前唯一一家提供免费ssl的cdn,注册完设置好nameserver之后大约等一个多小时,
网站就可以使用https访问了.
ssllabs的测试结果:
从图中可以看到,浏览器必须支持sni. - 然后就是让用户的http请求跳转到https.
在
layout/_scripts目录下加一个 script,然后在layout/_layout.swig中 include 进去.
<script type="text/javascript">
var host = "yoursite.com";
if ((host == window.location.host) && (window.location.protocol != "https:"))
window.location.protocol = "https";
</script>
- 设置网站的url,让google等搜索引擎知道你正在使用ssl.
在
_config.yml中增加:
url: https://www.yoursite.com # with the https protocol
enforce_ssl: www.yoursite.com # without any protocol
参考: Set Up SSL on Github Pages With Custom Domains for Free HTTPS下点击页面自动跳转HTTP