GitHub Pages Custom Domains


Outline
  1. 1. Basic 預備知識與情境說明
  2. 2. CASE I: A record to User Pages
  3. 3. CASE II: ALIAS to Project Pages
  4. 4. Reference

這邊為一個記錄將 Github Page 自定義到你所擁有的 Domain 下的一個流程。當然這些流程在 Goolge 搜尋 Github Page 就可以直接找到英文的說明文件,非常的詳細,此處就當做漢化的以及我自己碰到情境的過程記錄。

  • CASE I: http://evenchange4.github.io -> http://michaelhsu.tw
  • CASE II: http://about.michaelhsu.tw -> http://evenchange4.github.io/about

Basic 預備知識與情境說明

GitHub Pages 分為兩種:

  1. User Pages: 例如 http://evenchange4.github.io,每個帳號都只有一個,必須命名為 evenchange4.github.io,且在 master branch。
  2. Project Pages: 例如 http://evenchange4.github.io/about,也就是你的 GitHub 每一個 repository 都可以有一個 Page,必須在 gh-pages branch。

你可以注意到上面兩個例子可以分別導到我所擁有的 Domain name michaelhsu.tw,這是怎麼做到的呢?以下兩個情境依序帶你做設定。我這邊使用的 DNS provider 是 Godaddy

CASE I: A record to User Pages

也就是例子中的將 http://evenchange4.github.io 導到 http://michaelhsu.tw

  1. repository 中的 evenchange4.github.com master branch 新增 CNAME 檔案,內容為一行 michaelhsu.tw
  2. 將 Godaddy 新增 A record to 以下兩個 IP (兩個都要)
    • 192.30.252.153
    • 192.30.252.154

▲ Figure: A record to User Pages

需跳別注意 207.97.227.245 or 204.232.175.78 是舊的。

CASE II: ALIAS to Project Pages

大致上 CASE I 兩步驟設定完畢就可以直接由 http://about.michaelhsu.tw 導到 http://evenchange4.github.io/about,但是如果我想要自定義到 該怎麼做?

  1. repository 中的 about gh-pages branch 新增 CNAME 檔案,內容為一行 about.michaelhsu.tw
  2. 將 Godaddy 新增 CNAME record to evenchange4.github.io

▲ Figure: ALIAS to Project Pages

最後可以用 dig 來檢查:

1
2
3
4
5
6
7
8
$ dig about.michaelhsu.tw +nostats +nocomments +nocmd +multiline
=>
; <<>> DiG 9.8.3-P1 <<>> about.michaelhsu.tw +nostats +nocomments +nocmd +multiline
;; global options: +cmd
;about.michaelhsu.tw. IN A
about.michaelhsu.tw. 3600 IN CNAME evenchange4.github.io.
evenchange4.github.io. 3600 IN CNAME github.map.fastly.net.
github.map.fastly.net. 19 IN A 199.27.79.133

Reference