Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to set domain for Github website

📅 2019-Sep-08 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ domain, github ⬩ 📚 Archive

Github can be used to host a static website as described here. Github also allows you point your own domain at your Github website.

There are two methods to map your domain to your Github website: redirect and DNS. For both these methods you should have already bought a domain from a provider like Dreamhost.

Redirect

This method only redirects your domain foobar.com to your Github website root URL your-username.github.io. That is, if you type foobar.com into your browser, the browser is redirected to your-username.github.io. You will see the Github URL in the browser’s addressbar.

This method is highly restricted too, because you cannot type foobar.com/some/path/joe.html to get to your-username.github.io/some/path/joe.html. The redirection is strictly on the bare domain name.

The advantage of this method is that setting it up is easy. In Dreamhost, I went to Manage Domains section and setup these details:

Domain to redirect: foobar.com
Redirect to URL: your-username.github.io

The redirection was working after a few minutes.

DNS

This method completely maps your domain to the Github website. When you type foobar.com or foobar.com/some/path/joe.html, that is transparently mapped to your-username.github.io or your-username.github.io/some/path/joe.html without ever showing the latter URLs in the browser. A normal visitor of foobar.com cannot easily realize that your website is being hosted by Github.

This method takes a lot more steps, I have shared what I followed with Dreamhost below:

I found that the IP addresses listed were:

185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
Name: foobar.com
Type: A
Value: 185.199.108.153
$ dig your-username.github.io +noall +answer

; <<>> DiG 9.11.3-1ubuntu1.8-Ubuntu <<>> your-username.github.io +noall +answer
;; global options: +cmd
your-username.github.io.      3600    IN      A       185.199.108.153
your-username.github.io.      3600    IN      A       185.199.109.153
your-username.github.io.      3600    IN      A       185.199.110.153
your-username.github.io.      3600    IN      A       185.199.111.153

$ dig foobar.com +noall +answer

; <<>> DiG 9.11.3-1ubuntu1.8-Ubuntu <<>> foobar.com +noall +answer
;; global options: +cmd
foobar.com.      3600    IN      A       185.199.108.153
foobar.com.      3600    IN      A       185.199.109.153
foobar.com.      3600    IN      A       185.199.110.153
foobar.com.      3600    IN      A       185.199.111.153

If you don’t see your domain mapping to the Github IP addresses, then give it some time. It might take a while for the records to propagate.

Name: www.foobar.com
Type: CNAME
Value: your-username.github.io

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧