Publish a Website with GitHub Pages + Cloudflare DNS/SSL
A complete walkthrough for hosting your site on GitHub Pages with a custom domain, Cloudflare DNS, and HTTPS.
This guide walks you through:
- Buying a domain in Cloudflare
- Hosting your site on GitHub Pages
- Pointing your domain at GitHub using DNS records
- Enabling HTTPS (SSL)
Prerequisites
- A Cloudflare account
- A GitHub account
- A project/repo you want to host (or a new one)
1) Purchase a Domain in Cloudflare
- Log into Cloudflare
- Buy a domain (or transfer one in)
- Confirm the domain appears in your Account Home list
2) Create a New GitHub Repository
- Create a new repo on GitHub
- Put your website files in it (at minimum, an
index.htmlin the repo root)
3) Enable GitHub Pages
In your GitHub repo, go to: Settings → Pages
Under Build and deployment, set:
- Source: "Deploy from a branch"
- Branch:
main(and/rootunless you're using/docs)
GitHub will generate a Pages URL for you (something like https://<user>.github.io/<repo>/) once it builds.
4) Add Your Custom Domain in GitHub Pages
In Settings → Pages, find Custom domain
Enter your domain:
- If you want the root domain:
example.com - If you want the www version:
www.example.com
Save. This triggers a DNS verification check that will fail until you add DNS records in Cloudflare.
5) Open Your Domain in Cloudflare
- Go to Cloudflare Dashboard
- Click your new domain
- In the left sidebar, go to DNS → Records
6) Add DNS Records (A + CNAME)
A Records (for the apex/root domain)
Create 4 records with these settings:
| Type | Name | IPv4 Address | Proxy | TTL |
|---|---|---|---|---|
| A | @ | 185.199.108.153 |
DNS only | Auto |
| A | @ | 185.199.109.153 |
DNS only | Auto |
| A | @ | 185.199.110.153 |
DNS only | Auto |
| A | @ | 185.199.111.153 |
DNS only | Auto |
These are GitHub Pages' IPs for custom domains. All four are required for reliability.
CNAME Record (for www)
| Type | Name | Target | Proxy | TTL |
|---|---|---|---|---|
| CNAME | www | <user>.github.io |
DNS only | Auto |
Common mistake: Putting only the repo name (like my-site) as the CNAME target. That is not a real hostname. Use <user>.github.io unless GitHub explicitly tells you otherwise.
7) Set Cloudflare SSL/TLS Mode
- In Cloudflare sidebar, go to SSL/TLS
- Find the encryption mode box and click Configure
- Select: Full (strict)
8) Finish HTTPS in GitHub Pages
- Go back to your repo: Settings → Pages
- Wait for the DNS check to show successful (this can take a bit)
- Enable Enforce HTTPS
9) Start Building Your Site
- Open your IDE
- Clone the repo (if you haven't):
git clone <your-repo-url> - Make changes, commit, push to main
- GitHub Pages redeploys automatically
Troubleshooting
DNS check won't pass:
Confirm Cloudflare records are set to DNS only, not proxied.
Site loads on www but not root (or vice versa):
Make sure you added the 4 A records for the root and the CNAME for www.
HTTPS not working:
Cloudflare mode must be Full (strict) and GitHub must have Enforce HTTPS enabled.
Wrong CNAME target:
Use <user>.github.io (not the repository name).
You're Done
Your domain should now serve your GitHub Pages site over HTTPS. Go make something nice, or at least something that loads.