Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active November 14, 2024 07:55
Show Gist options
  • Save plembo/84f80c920bb5ac6f19e53fe6f8db1ff7 to your computer and use it in GitHub Desktop.
Save plembo/84f80c920bb5ac6f19e53fe6f8db1ff7 to your computer and use it in GitHub Desktop.
GitHub Pages with Namecheap custom domain

Using GitHub Pages with a custom domain: Namecheap Edition

As often happens, I found the official documentation and forum answers to be "close, but no cigar", and so had to experiment a little to get things working.

The main problem for me was a lack of concrete configuration examples. That's not entirely GitHub's fault: having migrated from Google Domains to Namecheap in the middle of this project, I was once again reminded of how many different ways there are to do things in the name service universe [1].

Although you'd think the simplest setup would be to merely configure for the subdomain case (https://www.example.com), in my experience using the apex domain (https://example.com) instead resulted in fewer complications.

Procedure

So here's my recipe for using a custom domain with GitHub pages where Namecheap is the DNS provider:

  1. Create A records for apex domain in Namecheap Advanced DNS panel for the domain(in this example, the fictional "example.com"):
Record Type Host Address TTL
A Record @ 185.199.108.153 30 minutes
A Record @ 185.199.109.153 30 minutes
A Record @ 185.199.110.153 30 minutes
A Record @ 185.199.111.153 30 minutes
CNAME Record www youracctname.github.io 30 minutes
  1. Wait an hour, then test if DNS is set up properly:
me@myhost:~$ dig +noall +answer +nocmd example.com
example.com.		1800	IN	A	185.199.110.153
example.com.		1800	IN	A	185.199.109.153
example.com.		1800	IN	A	185.199.108.153
example.com.		1800	IN	A	185.199.111.153
me@myhost:~$ dig +noall +answer +nocmd www.example.com
www.example.com.	1800	IN	CNAME	youracctname.github.io.
youracctname.github.io.	3600	IN	A	185.199.108.153
youracctname.github.io.	3600	IN	A	185.199.111.153
youracctname.github.io.	3600	IN	A	185.199.110.153
youracctname.github.io.	3600	IN	A	185.199.109.153
  1. In the GitHub repo config for Pages (Settings... Pages), enter your apex domain, "example.com" (not "www.example.com") in the "Custom Domain" box.

  2. Wait for GitHub to generate and install the SSL certificate for that apex domain (at least an hour).

  3. Test by going to "https://example.com" and "https://www.example.com".

I highly recommend not changing domain registrars and DNS providers in the middle of all that.

Notes

[1] The other problem is how damned long it takes for things to propagate across global DNS, especially when starting with TTLs of an hour (the trick is to try reducing your TTL before making any other changes, going from an hour to fifteen minutes can make a huge difference in blood pressure readings). Even with shorter TTLs, you need to anticipate upwards of an hour delay between changes. So chill. Read a book. Talk to the dog.

Further Reading

"Configuring a custom domain for your GitHub Pages site". GitHub Docs, https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site, Retrieved 9 September 2021.

"How do I link my domain to GitHub Pages". Namecheap Knowledgebase, https://www.namecheap.com/support/knowledgebase/article.aspx/9645/2208/how-do-i-link-my-domain-to-github-pages/, Retrieved 10 September 2021.

@leonardomarcao
Copy link

Thank you so much!

@realcapobambino
Copy link

Thanks. This helped me alot. 👌🏿

@pantasio
Copy link

Verify domain, Create TXT record with:
Host: "_github-pages-challenge-ORGANIZATION" or "_github-pages-challenge-YOURUSERNAME"
Value: "PRESS-COPY-BUTTON"

Read more detail:
https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/verifying-your-custom-domain-for-github-pages

@StonerWitches
Copy link

Hey, thanks! This was super helpful. The GitHub documentation could benefit from your input.

@ThisIsMirk
Copy link

Huge thanks for this very clear step by step instruction.

Copy link

ghost commented Jul 28, 2023

Thank you, this worked for my organisation's domain name too! 🚀🚀✅

@Declan-Reid
Copy link

I only realised from this that I have to use *.github.io instead of the domain that my pages use. Thank you!

@alpinus4
Copy link

Thanks! :)

@bunny-party
Copy link

I only realised from this that I have to use *.github.io instead of the domain that my pages use. Thank you!

can i ask what you mean by this? will this work instead? im having a lot of problems doing this process as a full beginner with my very first custom domain.

@RatriaSeza
Copy link

Can I rename the dns on namecheap ?

@plembo
Copy link
Author

plembo commented Feb 9, 2024

Not sure what you're asking.

@ushk-git
Copy link

@hwedi To add a subdomain, (i.e. sub.text.com) open up your domain settings on namecheap (Domain List, Manage), ensure that your nameservers is NameCheap BasicDNS, go to Advanced DNS, under Host Records, create a new CNAME record, and under host, let that be your subdomain (what precedes the dot), and then under the target, make that your github pages link, i.e. cat.github.io, then you shall get a subdomain.

@shrreyasbharath
Copy link

DUDDE thank u bro ,i got the enforce https button thank u bro

@telos-matter
Copy link

Thank you big man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment