Blog已成功從Hexo遷移到Hugo,新域名AxdLog。由於Github Pages對自有域名不提供SSL證書,故須額外部署。CloudFlare提供免費的SSL證書,並且提供防DDOS攻擊功能。
本文記錄如何配置並使用CloudFlare的SSL證書。
本文是 個人靜態博客構建系列 之一:
- 利用Travis CI和Hugo將Blog自動部署到Github Pages
- 爲GitHub Pages配置Cloudflare的免費SSL數字證書
- 爲已集成Travis CI的GitHub項目配置Slack信息推送
配置 Cloudflare
須先註冊CloudFlare帳號,若已經有,直接登入。
添加站點
若是新註冊用戶,登入後,出現 Add your site 頁面,輸入需要配置的域名。此處輸入axdlog.com
。
點擊Add site
按鈕後,出現 We’re querying your DNS records 頁面
點擊Next
按鈕,出現 Select a Plan 頁面。
選擇CloudFlare套餐
套餐價格如下
type | price |
---|---|
Free Website | $0/mon |
Pro Website | $20/mon |
Business Website | $200/mon |
Enterprise | Get in touch |
建議有經濟能力的選擇Pro
或Business
套餐,一是功能更多,二也算支持Cloudflare發展。此處,選擇Free Website
,點擊按鈕Confirm Plan
,出現 DNS query results 頁面
添加DNS記錄
顯示該域名當前的DNS記錄,刪除所有已有的記錄,新建2個CNAME
記錄。
以下是本人的DNS Records
Type | Name | Value | TTL | Status |
---|---|---|---|---|
CNAME | axdlog.com |
maxdsre.github.io |
Automatic | On CloudFlare |
CNAME | www |
maxdsre.github.io |
Automatic | On CloudFlare |
操作完成後,出現 Change your Nameservers 頁面
更換 Nameservers
CloudFlare提供了2組DNS地址
- dina.ns.cloudflare.com
- roan.ns.cloudflare.com
本人的域名註冊商是Namecheap,在Domain List
中選擇目標域名,在NAMESERVERS
中選擇custom dns
,將CloudFlare提供的2組DNS地址添加進去。
操作完成後,返回CloudFlare的 Change your Nameservers 頁面,點擊Continue
按鈕。
更新 Nameservers
頁面顯示如下信息
Status: Website not active (DNS modification pending)
Please ensure your website is using the nameservers provided:
- brianna.ns.cloudflare.com
- kurt.ns.cloudflare.com
Allow up to 24 hours for this change to be processed. There will be no downtime when you switch your name servers. Traffic will gracefully roll from your old name servers to the new name servers without interruption. Your site will remain available throughout the switch
當在域名提供商處修改好Nameservers
後,可點擊右側的Recheck Nameservers
檢測是否生效。此處請耐心等待,域名解析需要等一段時間才能生效。
如果檢測通過,則 Status: Pending
會變成 Status: Active
,並提示This website is active on CloudFlare.
。
Crypto 配置
Manage Cryptography settings for your website.
返回頁面頂部,有Cryptos
圖標點擊進入。
SSL
選項有四種選擇Off
、Flexible
、Full
、Strict
,點擊下方的Help
,可查看相關解釋說明。
查閱的參考教程大都推薦Flexible
,而本人則參考Set up cloudflare,選擇Full
。
接下來設置HTTP Strict Transport Security (HSTS)
,點擊其右側的Enable HSTS
進入,勾選I understand
,點擊Nest step
,開啓如下兩項
Apply HSTS policy to subdomains (includeSubDomains)
No-Sniff Header
點擊Save
保存退出。
其餘的功能,可自行設置。
配置 Hugo
Hugo的設置要比Hexo簡單,只需在repo(maxdsre.github.io)的master
分支中添加名爲CNAME
的文件即可。將自有域名地址寫入該文件,此處寫入axdlog.com
。
因爲是通過Travis CI進行集成部署,故而只需在.travis.yml
文件添加一行設置。
|
|
測試
在瀏覽器中測試,能正常跳轉到https
,並顯示綠色小鎖。在Google Chrome
和Mozilla Firefox
上測試通過。
當初爲Hexo配置SSL證書耗費了5個多小時,而現在整個過程不超過半個小時。
參考資料
- Set Up SSL on Github Pages With Custom Domains for Free
- How To Add Free Cloudflare SSL in Github Pages with Custom Domain?
- Hexo blog with custom domain and cloudflare
更新日誌
- 2018.04.11 16:05 Wed America/Boston
- 初稿完成