Saturday, January 09, 2016

Static sites on Github with a Custom Domain

I recently tried hosting a static site on Github with a custom domain. Github's docs on getting this done are unnecessarily confusing. Here's a quick snapshot of how to get this done quickly: I'm going to use the zigndog.com Github repo as an example. The custom domain is zigndog.com. You can just change the values in the 2 bash variables below and execute the same sequence of steps.



Verify that everything worked by visiting your website published on Github:
eg. http://divyekapoor.github.io/zigndog.com/ for the zigndog.com repo. If you have a different repo name, just use that along with your username: eg. http://${GITHUB_USER}.github.io/${REPO_NAME}

Next, visit your domain's DNS registrar and add a DNS A record pointing to Github. The Github static IP addresses are detailed here: https://help.github.com/articles/tips-for-configuring-an-a-record-with-your-dns-provider/. For reference, at the time I did my configuration, they were:

  • 192.30.252.153
  • 192.30.252.154

Make sure that you set up a DNS A record (probably in some Advanced Configuration section). Don't bother with any of the CNAME stuff (it's not useful). I can't really help much with this step since each registrar is different. Make sure you set up 4 A records: 2 for the root domain and 2 for the "www" subdomain (one for each of the IPs above).

Once everything is set up, wait for the DNS changes to propagate:
$ dig ${DOMAIN} +nostats +nocomments +nocmd

The output should look somewhat like:

$ dig zigndog.com +nostats +nocomments +nocmd
; zigndog.com
zigndog.com    73  IN  A 192.30.252.153
zigndog.com    73  IN  A 192.30.252.154

Hope that fixes things for you and gets you done sooner. Let me know if you face any issues in the comments.

Cheers!
Divye