📅 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.
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.
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:
In the Dreamhost console, go to Manage Domains and choose the DNS option. Once this is setup, go to the DNS section to set up your DNS records.
In the Dreamhost DNS setup page, there are many sections. At the bottom are permanent immutable DNS records in the Non-editable DreamHost DNS records for foobar.com section. At the top is a form named Add a custom DNS record to foobar.com. We will use this form multiple times to add DNS records for our domain. Every record we add will appear below in the Your custom DNS records for foobar.com section.
Go to the Github documentation for setting up an apex domain and note down the IP addresses listed in the A
records section.
I found that the IP addresses listed were:
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
A
records for them one by one. In the Dreamhost DNS setup page, use the form to add A
records for every one of the above IP addresses. For example, one entry I added in the form would look like:Name: foobar.com
Type: A
Value: 185.199.108.153
dig
tool. Both foobar.com
and your-username.github.io
should list the same Github IP addresses:$ 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.
www
subdomain to the Github website too. In the Dreamhost DNS setup page, add a CNAME
record for this mapping:Name: www.foobar.com
Type: CNAME
Value: your-username.github.io
Back at Github, go to the Settings section of the your-username.github.io
repository. In the Github Pages section, add foobar.com
to the Custom Domain field and save it.
Note that propagation of DNS records might take several hours. Until then your domain will not work and the Github settings might also complain that the DNS is not working. Dreamhost has an option to refresh DNS records for the domain. Since I did not see my domain working even after a few hours, I had to resort to this Dreamhost refresh option. After an hour of doing that I saw my domain work normally.