10

GitHub updated their Pages service for custom domains yesterday and I'm not clear on one small detail. They recommend a CNAME record for www.example.com but do not recommend using A records for the apex domain.

I want to make sure both example.com and www.example.com resolve correctly to www.example.com, and also get the benefit of GitHub's new CDN. Do I use a CNAME for www only then, with no A record at all?

This feels like a dumb question as I type but I'm just not getting it.

Tom Brossman
  • 2,291
  • 16
  • 20

2 Answers2

5

Do I use a CNAME for www only then, with no A record at all?

You would need to use a CNAME for the www.example.com subdomain, and an ALIAS record for your root domain example.com (aka., "apex domain").

As indicated in the help document you provided on Setting up a custom domain with Pages:

Some DNS providers (like DNSimple) allow you to use an ALIAS record to point your custom apex domain to username.github.io. If your DNS provider supports this it will allow us to provide the full benefits of our Content Delivery Network to your Page.

Elaborating on this using their DNSimple reference, an ALIAS record is:

...a virtual record type that we created to provide CNAME-like behavior on apex domains.

For example, if your domain is example.com and you want it to point to a host name like myapp.herokuapp.com, then you cannot use a CNAME record, but you can use an ALIAS record. The ALIAS record will automatically resolve your domain to one or more A records at resolution time and thus resolvers see your domain simply as if it had A records.

The example DNSimple provides for setting an ALIAS record is here (substitute username.github.io for the Heroku server in that example).

For other DNS providers, see their support docs on how to set an ALIAS record to a subdomain. If your DNS provider does not support setting ALIAS records, then you'll have to use an A instead, which will not provide the benefit of GitHub's CDN.

dan
  • 15,153
  • 11
  • 46
  • 52
5

According to https://help.github.com/articles/tips-for-configuring-an-a-record-with-your-dns-provider/#configuring-a-www-subdomain

If you configure both an apex domain (e.g. example.com) and a matching www subdomain (e.g. www.example.com), GitHub's servers will automatically create redirects between the two.

Here is my setup that seems to work correctly:

  • in my DNS:

    • I've got a CNAME record for www.my-domain-name.com pointing to myusername.github.io
    • I've got an A record for my-domain-name.com pointing to 192.30.252.153 and 192.30.252.154
  • in my ghpages repo, my CNAME file contains www.my-domain-name.com

And this setup seems to work with Github's CDN.

CharlieC
  • 151
  • 1
  • 2