To set up custom domain with HTTPS on Github Pages, there are 6 steps :
- Buy domain
- Setup Github Pages CNAME
- Add domain to Cloudflare
- Setup Cloudflare A record
- Change DNS Nameservers
- 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 :
192.30.252.153
192.30.252.154
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 :
mia.ns.cloudflare.com
woz.ns.cloudflare.com
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 !