Multiple custom domains with GitHub hosting
As described in earlier posts, I host this website and blog using GitHub Pages. I also host www.deeplearningbook.org using GitHub pages from the same GitHub account. Recently, I decided to start using a custom domain for this website. I found the GitHub documentation for how to do so to be somewhat confusing, and found other people struggling with the same issue, but did not find the solution posted anywhere, so I decided I should write down what I ended up doing.
Some of the GitHub documentation is ambiguous, and makes it sound to me as if it might not be possible to use multiple custom domain names with a single user accounts. Examples in the documentation use a single custom domain with different repositories being mapped to different subdomains or directories under a domain.
Fortunately, GitHub does support different custom domains for each repository. Setting them up is relatively simple once you know what to do, though figuring it out by trial and error can be problematic since errors will take your site down and take some time to fix due to the time it takes for DNS updates to propagate. Some of my readers may have noticed that www.deeplearningbook.org had some downtime while I was figuring this out.
Suppose we wish to take the GitHub pages hosted at username.github.io/repo_n
and have them appear at www.custom_domain_n.com
, for multiple values of n
.
The solution is:
* Using your domain name registrar (I use www.namecheap.com), for each www.custom_domain_n.com
:
* Add an A record with host @
and value 192.30.252.153
. Some of the GitHub
documentation seems to discourage the A record approach, but it is the only approach that worked
for me.
* Add an A record with host @
and value 192.30.252.154
.
* Add a CNAME record with host www
and value username.github.io.
Yes, there is supposed to be a .
at the end of the value.
Some pages of the GitHub documentation seem to suggest that multiple domain names
will not all be support if they have a CNAME Record pointing to the same user account,
but this is fortunately not the correct interpretation of the documentation.
* You may also wish to add a URL redirect record so that custom_domain_n.com
will take you to
www.custom_domain_n.com
.
* On GitHub, for each repository, add the corresponding custom domain in the repository’s settings.
Using this approach, I was able to link www.iangoodfellow.com to goodfeli.github.io and www.deeplearningbook.org to goodfeli.github.io/book .