Using a custom domain name can be important for personal marketing and offers one greater freedom to in choosing their domain representation (GitHub Pages requires the domain name <your_domain>.github.io
).
Purchasing a domain name
Guide: https://help.github.com/articles/using-a-custom-domain-with-github-pages/
-
Go to domains.google.com and purchase whatever domain you want ($12 / year usually).
-
Create a file called CNAME in the main directory of your github repo. Add the lines
<your_domain>
andwww.<your_domain>
(e.g.example.com
andwww.example.com
). -
Open up the DNS settings for your site on https://domains.google.com/registrar.
-
Under “Name servers”, click “Use the Google Domains name servers”.
-
Under “Custom resource records”, create the following records:
- @, A, 1h, 185.199.108.153, (click the + button) 185.199.109.153, (click the + button) 185.199.110.153, (click the + button) 185.199.111.153
- www, CNAME, 1h,
https://<your_username>.github.io/.<your_domain_name>.
These records tell Google’s DNS to point to GitHub to find your page.
Securing your site with HTTPS
Guide: https://gist.github.com/cvan/8630f847f579f90e0c014dc5199c337b
By default, github pages doesn’t support access to your site with HTTPS with a custom domain. This means that whenever someone clicks on your site after a google search, they’ll see a warning saying your site might be trying to steal your data. We don’t want this!
-
Set up a free cloudflare account here: https://www.cloudflare.com/ and add your website to your account.
-
Under the DNS settings for your site on Cloudflare, go to “DNS Records”.
- Set up the following DNS Records:
- A,
<your_domain_name>
, 185.199.108.153, Automatic TTL - A,
<your_domain_name>
, 185.199.109.153, Automatic TTL - A,
<your_domain_name>
, 185.199.110.153, Automatic TTL - A,
<your_domain_name>
, 185.199.111.153, Automatic TTL - CNAME, www,
<your_domain_name>
Note:
<your_domain_name>
should be likeexample.com
, NOTwww.example.com
norhttp://example.com
- A,
- Scroll down to Cloudflare Nameservers and take note of the two nameservers provided to you.
- Some examples are lorna.ns.cloudflare.com and phil.ns.cloudflare.com.
-
Under the Crypto settings for your site on Cloudflare, scroll to “SSL” and ensure that Full SSL encryption is being used.
-
Scroll to “Always use HTTPS” and flick the switch to “On”.
-
Go back to the DNS settings at https://domains.google.com/registrar and go to “Name servers”.
- Click “Use custom name servers” and input the two name servers provided to you by Cloudflare.