Github Website with a Custom Domain & SSL
step 0: buy a domain name
For these instructions use the (Namecheap)[https://www.namecheap.com/] service to buy your Domain.
step 1: point your domain name at: username.github.io (optional)
This takes quite a steps and disables https (more steps follow to renable ssl). This article got me oriented: https://dev.to/rightfrombasics/connecting-namecheap-domain-with-github-pages-3nn6
- log into Namecheap
- On the left is a sidebar with Dashboard and the top. Click on the Domain List
- Find your domain name and click the manage button on the far right.
- Along the top click on Advanced DNS
- Add your A records to the DNS config. I typed:
dig btihen.github.io
(of course replace with your github website name) and got:
; <<>> DiG 9.10.6 <<>> btihen.github.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28239
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;btihen.github.io. IN A
;; ANSWER SECTION:
btihen.github.io. 3600 IN A 185.199.110.153
btihen.github.io. 3600 IN A 185.199.109.153
btihen.github.io. 3600 IN A 185.199.108.153
btihen.github.io. 3600 IN A 185.199.111.153
So created the following A Records:
type Host Value TTL
A Record @ 185.199.110.153 Automatic
A Record @ 185.199.109.153 Automatic
A Record @ 185.199.108.153 Automatic
A Record @ 185.199.111.153 Automatic
- Then I created a CNAME record:
type Host Value TTL
CNAME Record www btihen.github.io Automatic
step 2: configure you github site to accept the domain
You need to make a file called CNAME in the root of your username.github.io repo and it contents must be your new domain name.
For example I used:
cd public
touch CNAME
echo 'btihen.me' >> CNAME
git add .
git commit -m 'accept the domain name: btihen.me'
git push
step 3: stop and check
NOW: http://your-domain-name.com
should work
step 4: Free ssl for the domain
following the advice from: https://dev.to/rightfrombasics/adding-ssl-to-your-site-free-1fa7
- create a cloudflare account.
- choose the dns feature
- allow cloudflare to scan your dns records (it should get the same results as when you do:
dig username.github.io
) - Continue through the cloudflare process & cloudflare will eventually give you 2 nameservers to use.
- Now you can have cloudflare take over your dns – log into Namecheap
- On the left is a sidebar with Dashboard and the top. Click on the Domain List
- Find your domain name and click the manage button on the far right.
- On the top bar choose Domain
- Find the Nameservers section
- Choose Custom DNS
- Add the tow servers given to you by Cloudflare and save.
- Go back to cloudflare and choose Full end to end encryption
- Choose Always Use HTTPS
- Save and click the Re-check now button.
Unfortunately, now you need to wait for a 1/2 hour or morefor the dns service to transfer from Namecheap to Cloudflare. Theoretically up to 48 hours (but a 1/2 hour is much more typical).