I recently got started with Github pages as a cheap and easy solution to deploy static pages and wanted to use a custom domain. So I bought a domain from Eurodns and was trying to configure Github pages to play nicely with it. In the process I realised I had forgotten some of the DNS basics - so here they are, maybe they help someone else.
This post is about DNS in general with some specifics to Eurodns, Github pages and Heroku apps.
DNS is the protocol used to translate from domain names to IPs. It is an application layer (remember the TCP/IP model)? Some terminology: DNS zone, DNS record, FQDN/PQDN Fully/Partial Qualified Domain Names, TTL(Time To Live).
There are many types of records, I will only focus on what I needed:
Arecords point from a domain name to an IPv4. This is not great because in case something changes in your network, you need to manually update IPs.
AAAArecords is the same but points to an IPv6.
CNAMErecords point to another domain instead of an IP. The destination domain can be in the same DNS zone or not (if not you append a "." at the end).
CNAMEis not very useful for 2 reasons:
…it isn’t possible to create a CNAME record at the apex – or root – of a domain.1
It should only be used when there are no other records on that name.2
Trying to tie 2 CNAMEs from the same domain in Eurodns gives a nice fat red error: "Round Robin is not allowed on CNAME"
ANAME) similar to CNAME but without those 2 restrictions.
URLredirects from a domain to a URL.
- I have registered the apex domain
spygi.me(without www). First thing is to create a
URLrecord from the
www.version of the domain to the non
www(you can choose 301, 302 or redirect in a frame). Apparently this sets up an
Arecord behind the scenes.
- On the Github repo itself you need a CNAME file (you can create this file yourself or go to repo settings->Github pages)
This accepts only FQDN (no path otherwise you will get a mail saying "The CNAME
foo/baris not properly formatted"!) and what it does is a 301 to the domain specified (which at this point points to nowhere).
To fix that you need a
APEX) from the FQDN you used before to
USERNAME.github.io.(notice the trailing dot) This way your users are able to access your app only on one URL - the custom one - which is better for the end-user I assume. I used a
- For Heroku, you only do the last step meaning if you navigate to your
app-name.herokuapp.comyou still see your app (besides on your custom domain). I used an
APEXsince I want to use my root domain
"Wildcards" have to do with SSL certificates (not with subdomains). Specifically they give you the chance to issue one certificate for all *.yourdomain.com for an additional charge (at least for Eurodns).
- Can I use DNS to point to a specific path? No
- Check your configuration with
- Latency in changes can be due to TTL (in case of existing records) or DNS propagation (in case of newly created records). Note that refreshing the browser (even bypassing the cache) does not invalidate the DNS cache. You can flush it in Chrome like this - or just open an Incognito window.