博客启用https(支持hexo)

  1. CloudFlare是目前唯一一家提供免费ssl的cdn,注册完设置好nameserver之后大约等一个多小时,
    网站就可以使用https访问了.
    ssllabs的测试结果:

    从图中可以看到,浏览器必须支持sni.
  2. 然后就是让用户的http请求跳转到https.
    layout/_scripts 目录下加一个 script,然后在 layout/_layout.swig 中 include 进去.

    1
    2
    3
    4
    5
    <script type="text/javascript">
    var host = "yoursite.com";
    if ((host == window.location.host) && (window.location.protocol != "https:"))
    window.location.protocol = "https";
    </script>

  3. 设置网站的url,让google等搜索引擎知道你正在使用ssl.
    _config.yml中增加:

    1
    2
    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