Github Page Domain CDN Acceleration05 Mar 2014 • Leave Comments
- Default domain
The github default domain is
username.github.iowhich is also a subdomain. But usually we need to use our own domain for blog. Personal domain may be top domain or subdomain. Subdomain is like
www.example.comwhile top domain is like
example.com. Github names
apexdomain (record). Here
apexdomain acctually is not a domain but a domain dns record.
The key is to set a
CNAMErecord for your github page
username.github.io. For example if you have a top domain
CNAMErecord is like:
This means subdomain address
www.example.com will be redirected to
- CNAME and Top domain
CNAMEdoes not support top domain. The following three lines are all illegal unless your DNS provider supports CNAME flattening (i.e. Clouflare), ALIAS and ANAME.
If you set
CNAME like this, it will direct all your other subdomains like mail, ftp etc to your github page. Refer to custom subdomain.
Do not use wildcard DNS records (e.g. *.example.com) with GitHub Pages! A wildcard DNS record will allow anyone to host a GitHub Pages site at one of your subdomains.
Can I use my top domain for acceleration? Yes, but not easy! First, your DNS provider must support
Alias DNS Record which is not a standard DNS record. Only a few DNS provider support this with fees, like dnssimple. Refer to What is an ALIAS record? and Pointing the Domain Apex to Heroku.
CNAMEfile (or by Github setting) at the root directory of github pages. You may find it uncessary at first. If you don't add this file, only the first time you enter the custom domain url works as you wish. If you further click some other links in the blog (i.e. a post), you will find the url changes to original username.github.io. This looks ugly. What was worse, The webbrower tab will not show the blog title.
Add your custom domain to your GitHub Pages site's repository before configuring your domain name with your DNS provider.
- In the
CNAMEfile, you can put only one line namely www.example.com there. Now Github handles everything in your jekyll blog with address www.example.com not the original username.github.io. Attention! Put bare address. Don't add
- Next need DNS support. I choose freenom to register my top domain example.tk. Why top domain? Not subdomain? Don't worry! Freenom supports top domain, why not get one? Yes, get the top domain. Then we can set a CNAME DNS record! Refer to How to setup A, MX, CNAME….
CNAMErecord is to transfer
WWWsubdomain of example.tk (namely www.example.tk) to username.github.io. Now wait for a while, it will be fine. Use
dig www.example.tkto test your result. Refer to use the dig command.
- But if you want example.tk also points to username.github.io, what should be done? As mentioned above we cannot use
CNAME. What is worse, freenom does not support
AliasDNS record like
dnssimpledoes. However we can set
Arecord for the top domain alghtough it does not support CDN. Please refer to configuring an A record on Github.
- Now you can access your blog from both subdomain and top domain. Although top domain does not support CDN individually, but if both subdomain CNAME and top domain A records are configured, github itsefl will create redirect between the two based on the CNAME file in the github page root directory. Refer to Configuring a www subdomain. Since the
CNAMEfile in github pages are
www.example.com, then when you input
example.comin your browser, github will redirects you to
For more detailed Top domain DNS CNAME discussion refer to 顶级域名不能设置DNS CNAME记录.