How to Point a Namecheap Domain to GitHub Pages with DNS and SSL

by Fahim

Your static site is live on username.github.io, but you want it running on your own Namecheap domain with valid SSL and no cert errors. Getting this right means configuring Namecheap’s DNS records, dropping a CNAME file in your repo, verifying domain ownership so nobody else claims it, and letting GitHub provision your Let’s Encrypt certificate.

How to Point a Namecheap Domain to GitHub Pages with DNS and SSL
How to Point a Namecheap Domain to GitHub Pages with DNS and SSL

1. GitHub Pages IP Addresses and the Apex DNS Problem

Pointing an apex domain (like example.com) is trickier than setting up a standard subdomain. DNS standards don’t let you put a CNAME at the zone apex because it clashes with your SOA and NS records. To get around this without CNAME flattening, GitHub gives us four Anycast IPv4 addresses to point our root domain at directly.

If you want the deep dive into why apex domains break CNAMEs across DNS providers, check out our guide on pointing root domains in Namecheap DNS with A records vs CNAME.

Here are the four GitHub Pages Anycast IPs you’ll need:

  • 185.199.108.153
  • 185.199.109.153
  • 185.199.110.153
  • 185.199.111.153

For your www subdomain (like www.example.com), you’ll point a standard CNAME record straight to username.github.io. GitHub handles the 301 redirect between the apex and www version automatically based on whichever domain you configure in your repo settings.

2. Adding the CNAME File to Your Repository

GitHub Pages needs to know which repository should answer incoming traffic for your domain. When someone hits example.com, GitHub’s edge routers look for a repo claiming that specific hostname. You claim it with a single CNAME file sitting in the root of your publishing branch.

Create a file called CNAME (all uppercase, no file extension) in your site’s root directory. If you’re using a static site generator like Astro, Hugo, or Next.js static export, drop it in your /public directory so your build doesn’t wipe it.

Add your primary domain as the only line in the file:

echo "example.com" > CNAME
git add CNAME
git commit -m "chore: add custom domain CNAME for github pages"
git push origin main

If you want your site to live on www.example.com and redirect root visitors there instead, put www.example.com in this file. GitHub treats whatever is inside CNAME as your canonical URL.

3. Configuring Namecheap Advanced DNS Records

Log in to Namecheap, open your Domain List, hit Manage next to your domain, and switch to the Advanced DNS tab. First things first: delete any default parking records, like Namecheap’s URL Redirect Record or parking page CNAMEs, or they’ll collide with your new settings.

Next, add four A Records for the apex domain and one CNAME Record for the www host:

  • Type: A Record | Host: @ | Value: 185.199.108.153 | TTL: Automatic
  • Type: A Record | Host: @ | Value: 185.199.109.153 | TTL: Automatic
  • Type: A Record | Host: @ | Value: 185.199.110.153 | TTL: Automatic
  • Type: A Record | Host: @ | Value: 185.199.111.153 | TTL: Automatic
  • Type: CNAME Record | Host: www | Value: username.github.io. | TTL: Automatic

If you’re also pointing sub-services or APIs elsewhere, take a look at how to route subdomains to different servers in Namecheap DNS without touching your root GitHub Pages setup.

Hit the green checkmark on each record to save your changes in Namecheap.

4. Verifying DNS Propagation with Terminal Tools

DNS changes usually take anywhere from 5 to 30 minutes to propagate. Before hitting save in GitHub and trying to generate SSL certificates, verify from your terminal that public DNS resolvers see the new IPs.

Run dig against your apex domain:

dig +noall +answer example.com A @8.8.8.8

You should see all four GitHub Pages Anycast IPs returned in the ANSWER section:

example.com. 300 IN A 185.199.108.153
example.com. 300 IN A 185.199.109.153
example.com. 300 IN A 185.199.110.153
example.com. 300 IN A 185.199.111.153

Now check your www CNAME record:

dig +noall +answer www.example.com CNAME @1.1.1.1

Once both resolve to GitHub’s infrastructure, you’re clear to set up HTTPS without hitting validation timeouts.

5. Verifying Domain Ownership in GitHub Account Settings

Always verify domain ownership on your GitHub profile or organization before going live. This stops domain takeover attacks, where an attacker discovers your DNS points to GitHub before you’ve linked the repo and claims your domain on their own account. You can read more about this in the official GitHub custom domain documentation.

Here’s how to lock it down:

  1. Click your profile avatar in GitHub and go to Settings.
  2. In the left sidebar under Code, planning, and automation, click Pages.
  3. Click Add a domain and type your apex domain (e.g., example.com).
  4. GitHub will give you a unique TXT record name and challenge string, formatted like _github-pages-challenge-username.

Head back to Namecheap’s Advanced DNS tab and add that TXT entry:

  • Type: TXT Record
  • Host: _github-pages-challenge-username
  • Value: (Your unique GitHub challenge code)
  • TTL: Automatic

Give it a minute or two, flip back to GitHub, and click Verify. Once it passes, a green badge confirms only your repositories can publish to this domain.

6. Enforcing HTTPS and Provisioning SSL

With your DNS propagating and the CNAME file in place, let’s turn on your live site settings:

  1. Open your GitHub repository and head to Settings > Pages.
  2. Under Custom domain, type example.com (or www.example.com) and click Save.
  3. GitHub runs an instant DNS check. Once it passes, you’ll see DNS check successful.
  4. Check the Enforce HTTPS box.

GitHub automatically provisions a free TLS certificate through Let’s Encrypt. If the Enforce HTTPS box is greyed out with a notice that the certificate is being issued, don’t panic. It usually finishes within 10 to 15 minutes.

Once it’s active, test the HTTP-to-HTTPS 301 redirect with curl:

curl -I http://example.com

You want to see an HTTP 301 Moved Permanently response with the location header pointing to https://example.com/.

7. Troubleshooting Common GitHub Pages DNS Errors

If your build finishes but your domain isn’t resolving cleanly, it’s usually one of these three gotchas:

Error 404 Site Not Found

If you see a GitHub 404 page at your custom domain, your DNS is working, but GitHub doesn’t know which repo should respond. Make sure your CNAME file exists in the root of the published branch (like gh-pages or main) and contains only the raw domain name—no https://, no paths, no trailing slashes.

TLS Certificate Stuck on Pending

If HTTPS issuance hangs for hours, check your Namecheap DNS for existing CAA (Certificate Authority Authorization) records. If you have CAA entries that only permit Sectigo or DigiCert, Let’s Encrypt won’t be able to issue a cert. Add a CAA record allowing letsencrypt.org or wipe the old CAA records. You can also review Namecheap’s GitHub Pages setup documentation for their baseline requirements.

Redirect Loop Between Apex and WWW

A classic redirect loop happens when Namecheap still has an active URL Redirect sending example.com to www.example.com, while your GitHub repo’s CNAME file is set to example.com. GitHub tries to redirect www to root while Namecheap redirects root to www. Delete all URL Redirect records in Namecheap; GitHub handles canonical domain routing on its own.

If you end up migrating your project from static pages to containerized Node.js or PHP backends down the line, see our tutorial on how to deploy a web app with Namecheap DNS and SSL.

Frequently Asked Questions

Can I use an ALIAS or ANAME record in Namecheap instead of 4 A records?

No. Namecheap BasicDNS doesn’t support ANAME or ALIAS record flattening at the root apex. You need all four standard A records pointing to GitHub’s Anycast IPs (185.199.108.153 through .111.153).

How long does SSL certification take on GitHub Pages?

Let’s Encrypt certificates usually provision within 5 to 20 minutes once DNS propagates. If Namecheap had old cached records, it can take up to 24 hours in rare cases.

Will adding Namecheap DNS records overwrite my custom domain email?

No. As long as you only edit the root A records and the www CNAME, your existing MX, SPF, and DKIM TXT records will keep handling your mail without interruption.

Why does my CNAME file disappear after every deployment?

Build tools like Vite, Webpack, and Astro clean out the output directory on every compile. Put your CNAME file in the public/ folder so your build pipeline copies it cleanly into the final output bundle every time.

If you’re running local homelab setups or dynamic staging environments that need automated DNS updates, check out our guide on how to configure Dynamic DNS in Namecheap with Bash and Cron.

all_in_one_marketing_tool