Set up Github Pages custom domain with HTTPS

To set up custom domain with HTTPS on Github Pages, there are 6 steps :

  1. Buy domain
  2. Setup Github Pages CNAME
  3. Add domain to Cloudflare
  4. Setup Cloudflare A record
  5. Change DNS Nameservers
  6. Setup HTTPS in Cloudflare

Buy domain

Buy domain from provider like Godaddy, NameCheap

Setup Github Pages CNAME

Go to Repository -> settings -> Custom domain -> Type YOUR_CUSTOM_DOMAIN -> Save

Github will commit a file called CNAME contain YOUR_CUSTOM_DOMAIN in repository root like example.

Add domain to Cloudflare

Go to Cloudflare-> Sign up-> Add Site -> Type YOUR_CUSTOM_DOMAIN -> Begin Scan -> Continue Setup

Setup Cloudflare A record

In DNS page, add A record which point out by Github :

Change DNS Nameservers

After setup A record -> Selct plan -> Continue -> you will be asked to change dns nameservers which suggest by Cloudflare :

Now go to your domain provider, and change nameservers which suggest by Cloudflare :

Setup HTTPS in Cloudflare

Go to Page Rules -> Create Page Rule -> type http://*.{YOUR_CUSTOM_DOMAIN}/* -> Select Always Use HTTPS -> Save and Deploy

After few hours, you can start to access your Github Pages by your custom domain with HTTPS, also you got Cloudflare cdn service! Enjoy !