GitHub Pages Domain Setup with Cloudflare
This guide connects a custom domain to a GitHub Pages site using Cloudflare for authoritative DNS. It covers the required DNS records, nameserver migration, HTTPS, and an optional Cloudflare WAF rule.
Example values
Replace these examples with your own values:
| Setting | Example |
|---|
| Domain | exploring-data.com |
| Apex hostname | exploring-data.com |
www hostname | www.exploring-data.com |
| GitHub Pages hostname | yaph.github.io |
Use your GitHub account or organization hostname as the CNAME target. Do not include a repository name or path.
1. Verify the domain and configure GitHub Pages
Do this before pointing the website DNS records at GitHub Pages.
- In GitHub, open Settings → Pages → Verified domains (use organization settings for an organization-owned site).
- Add your apex domain and follow GitHub's instructions to create the supplied TXT record.
- Publish the exact TXT name and value at your current DNS provider. Keep this record permanently.
- After GitHub confirms verification, open the repository that publishes the site and go to Settings → Pages.
- Set Custom domain to
exploring-data.com and save.
GitHub recommends verifying ownership before adding the custom domain to the repository. Add the custom domain in GitHub before configuring its website DNS records.
2. Add the domain to Cloudflare
- Add
exploring-data.com to Cloudflare and choose your plan. - Review the imported records before changing nameservers.
- Preserve all records used by email, GitHub verification, and other services. In particular, make sure the GitHub verification TXT record is present in the Cloudflare zone with its exact value.
- Prepare the website records in Cloudflare as DNS-only (grey cloud) for initial GitHub Pages validation and certificate provisioning.
Cloudflare may import or create website records as Proxied by default. Check the proxy status explicitly.
Apex domain
Add the four GitHub Pages A records:
| Type | Name | Value | Proxy |
|---|
| A | @ | 185.199.108.153 | DNS-only |
| A | @ | 185.199.109.153 | DNS-only |
| A | @ | 185.199.110.153 | DNS-only |
| A | @ | 185.199.111.153 | DNS-only |
For IPv6 support, also add GitHub's four AAAA records:
| Type | Name | Value | Proxy |
|---|
| AAAA | @ | 2606:50c0:8000::153 | DNS-only |
| AAAA | @ | 2606:50c0:8001::153 | DNS-only |
| AAAA | @ | 2606:50c0:8002::153 | DNS-only |
| AAAA | @ | 2606:50c0:8003::153 | DNS-only |
@ means the apex domain. GitHub recommends retaining A records when adding AAAA records.
www hostname
Add one CNAME record:
| Type | Name | Value | Proxy |
|---|
| CNAME | www | yaph.github.io | DNS-only |
Replace the example target with your account or organization hostname. When the repository's custom domain is the apex domain and both DNS names are configured, GitHub Pages handles the canonical www redirect. Do not add a competing redirect rule.
Email and verification records
Keep existing MX, SPF, DKIM, DMARC, and other service records. Copy their exact values from the relevant provider; do not use example SPF or mail-server values. MX and TXT records are DNS-only.
Keep the GitHub _github-pages-challenge-... TXT record after verification.
CAA records
Do not add restrictive CAA records unless you need them. If CAA records already exist, make sure they allow Let's Encrypt (letsencrypt.org) for GitHub Pages. If Cloudflare proxying is used, also ensure Cloudflare's current Universal SSL certificate authorities are allowed. Cloudflare automatically adds its Universal SSL CAA entries when needed for zones that have CAA records.
Do not create wildcard DNS
Do not add a * A or CNAME record. GitHub warns that wildcard DNS can expose nested subdomains to domain-takeover risk, even when the apex domain is verified. Create records only for subdomains you actually use.
4. Change nameservers and enable DNSSEC
Nameserver migration
- Copy the exact Cloudflare nameservers assigned to the zone.
- At your registrar, replace the existing nameservers with only the Cloudflare-assigned pair.
- Wait until Cloudflare reports the zone as Active.
If DNSSEC is currently enabled at your old DNS provider, remove the old DS record at the registrar before changing nameservers. Wait for its TTL to expire at the parent zone. Otherwise, validating resolvers can return SERVFAIL. If your old provider supports Cloudflare's documented multi-signer migration, follow that procedure instead.
Enable DNSSEC in Cloudflare
After the zone is Active:
- In Cloudflare, open DNS → Settings and enable DNSSEC.
- Copy the DS record details Cloudflare provides.
- Add that DS record at your registrar.
- Verify that DNSSEC validates successfully.
If DNSSEC was not enabled at your previous provider, skip the old-DS removal step.
5. Verify GitHub Pages and HTTPS
While the website records are DNS-only, verify the DNS answers:
dig exploring-data.com A +short
dig exploring-data.com AAAA +short
dig www.exploring-data.com CNAME +short
The apex A/AAAA answers should match the GitHub Pages addresses above, and www should point to yaph.github.io. On Windows, use Resolve-DnsName.
Then:
- Return to the repository's Settings → Pages.
- Confirm GitHub recognizes the custom domain and wait for its HTTPS certificate to be provisioned.
- Enable Enforce HTTPS.
- Test both
https://exploring-data.com and https://www.exploring-data.com.
GitHub obtains and installs the custom-domain certificate after its DNS check succeeds. Certificate provisioning can take time; do not enable Cloudflare proxying before this step is complete.
6. Choose whether to use the Cloudflare proxy
This choice determines whether the WAF rule below actually protects the website.
- DNS-only: Visitors connect directly to GitHub Pages. GitHub Pages handles HTTPS. Cloudflare WAF, Cloudflare redirects, and Cloudflare edge caching do not process website requests.
- Proxied (orange cloud): Requests pass through Cloudflare, enabling its WAF and other edge features. Public DNS answers show Cloudflare IP addresses rather than GitHub's IP addresses.
For the simplest and most predictable GitHub Pages setup, keep the website records DNS-only. If Cloudflare WAF protection is required, you must proxy the apex A/AAAA records and the www CNAME after GitHub HTTPS is working. This is an advanced configuration: proxying hides the GitHub DNS answers used by GitHub's documented DNS check and can affect certificate provisioning or renewal. Test both hostnames after switching and monitor HTTPS status. If GitHub's certificate becomes unavailable, revert to DNS-only and resolve the GitHub Pages certificate issue.
If you enable proxying:
- Set all apex A/AAAA records and the
www CNAME to Proxied. Do not mix DNS-only and Proxied A/AAAA records for the same hostname; Cloudflare treats them all as proxied if one is proxied. - Wait until Cloudflare's Universal SSL certificate is active for the apex and
www hostnames. - Set SSL/TLS → Overview to Full (strict). GitHub Pages must present a valid certificate for the custom hostname.
- Do not use Flexible mode.
- Keep GitHub Pages Enforce HTTPS enabled.
If you need predictable Cloudflare WAF protection without this GitHub Pages proxy trade-off, consider hosting the site on Cloudflare Pages instead.
Cloudflare WAF custom rules inspect requests only when the website hostname is Proxied. A rule created while the records are DNS-only does not protect visitors' requests to GitHub Pages.
In Cloudflare, open Security → Security rules → Custom rules (the menu may also appear as Security → WAF → Custom rules). Create a rule using the Expression Editor. Cloudflare Free supports five custom rules per zone and supports the Block action; this expression does not use the Business/Enterprise-only regex operator.
Rule name: Block Vulnerability Scanners
Action: Block
Host scope: The expression is limited to exploring-data.com and www.exploring-data.com. Replace these with your actual site hostnames.
Expression:
http.request.uri.path wildcard "*/.env"
or http.request.uri.path wildcard "*/.env.*"
or http.request.uri.path wildcard "*/.env/*"
or http.request.uri.path wildcard "*/.envrc"
or http.request.uri.path wildcard "*/.git"
or http.request.uri.path wildcard "*/.git/*"
or http.request.uri.path wildcard "*/.svn"
or http.request.uri.path wildcard "*/.svn/*"
or http.request.uri.path wildcard "*/.hg"
or http.request.uri.path wildcard "*/.hg/*"
or http.request.uri.path wildcard "*/.bzr"
or http.request.uri.path wildcard "*/.bzr/*"
or http.request.uri.path wildcard "*/.aws"
or http.request.uri.path wildcard "*/.aws/*"
or http.request.uri.path wildcard "*/.ssh"
or http.request.uri.path wildcard "*/.ssh/*"
or http.request.uri.path wildcard "*/.terraform"
or http.request.uri.path wildcard "*/.terraform/*"
or http.request.uri.path wildcard "*/.htaccess"
or http.request.uri.path wildcard "*/.htpasswd"
or http.request.uri.path wildcard "*/.ds_store"
or http.request.uri.path wildcard "*/wp-config.php"
or http.request.uri.path wildcard "*/config.php"
or http.request.uri.path wildcard "*/configuration.php"
or http.request.uri.path wildcard "*/phpinfo.php"
or http.request.uri.path wildcard "*/info.php"
or http.request.uri.path wildcard "*/web.config"
or http.request.uri.path wildcard "*/docker-compose.yml"
or http.request.uri.path wildcard "*/docker-compose.yaml"
or http.request.uri.path wildcard "*/id_rsa"
or http.request.uri.path wildcard "*/id_dsa"
or http.request.uri.path wildcard "*/id_ecdsa"
or http.request.uri.path wildcard "*/id_ed25519"
or http.request.uri.path wildcard "*/id_ecdsa_sk"
or http.request.uri.path wildcard "*/id_ed25519_sk"
or http.request.uri.path wildcard "*/authorized_keys"
or http.request.uri.path wildcard "*/known_hosts"
or http.request.uri.path wildcard "*/.npmrc"
or http.request.uri.path wildcard "*/.yarnrc"
or http.request.uri.path wildcard "*/.pypirc"
or http.request.uri.path wildcard "*/.netrc"
or http.request.uri.path wildcard "*/.git-credentials"
or http.request.uri.path wildcard "*/.gitconfig"
or http.request.uri.path wildcard "*/.pgpass"
or http.request.uri.path wildcard "*/.my.cnf"
or http.request.uri.path wildcard "*/privkey.pem"
or http.request.uri.path wildcard "*/private.key"
or http.request.uri.path wildcard "*/server.key"
or http.request.uri.path wildcard "*/terraform.tfstate"
or http.request.uri.path wildcard "*/terraform.tfstate.backup"
or http.request.uri.path wildcard "*/.terraform.lock.hcl"
or http.request.uri.path wildcard "*/local.settings.json"
or http.request.uri.path wildcard "*/secrets.yml"
or http.request.uri.path wildcard "*/secrets.yaml"
What it matches:
.env files and variants, .envrc, and paths inside an .env directory..git, .svn, .hg, .bzr, .aws, .ssh, and .terraform directories, including their contents.- The listed server configuration, PHP configuration/diagnostic, Docker Compose, SSH key, credential, and Terraform state filenames at any directory depth.
The Cloudflare wildcard operator is case-insensitive. * matches zero or more characters, including /, and the entire path must match the pattern. This lets */config.php match both /config.php and /admin/config.php without matching unrelated names such as .gitignore or .github. All path conditions use this operator, so repeated lower() and ends_with() calls are unnecessary. The hostname check remains case-normalized. Keep Cloudflare Normalize incoming URLs enabled (the default) so URL-based rules evaluate normalized paths.
Examples:
| Request path | Result |
|---|
/.env | Block |
/app/.env.production | Block |
/.ENV.LOCAL | Block (case-insensitive) |
/.envrc | Block |
/.git/config | Block |
/admin/config.php | Block |
/.terraform/terraform.tfstate | Block |
/.github/workflows/deploy.yml | Not matched by the .git checks |
/.environment | Not matched by the .env checks |
Important: This is a path-based block list, not scanner identification. It does not identify scanners by IP, user agent, or behavior, and it cannot cover every possible sensitive filename. It blocks the listed names at any directory depth; files with additional suffixes (for example, config.php.bak) are not included unless separately added. Never commit secrets or private keys to a public repository.
Place this rule before broad Skip rules that could bypass it. Test harmless paths such as /.env.production, /.git/config, and /admin/config.php, then check the matching event in Cloudflare Security Events. Confirm ordinary pages and assets still load.
This expression uses Cloudflare's case-insensitive wildcard operator rather than regular expressions, so it does not require the Business/Enterprise regex feature. Cloudflare documents a 4,096-character expression limit; this expression is 2915 characters (excluding the surrounding Markdown code fence).
Final checklist
- [ ] Domain verified in the correct GitHub personal or organization settings.
- [ ] Custom domain saved in repository Settings → Pages before website DNS was configured.
- [ ] GitHub verification TXT record retained in Cloudflare DNS.
- [ ] Apex A records configured; AAAA records added if IPv6 is required.
- [ ]
www CNAME points to the account or organization github.io hostname. - [ ] No wildcard DNS record exists.
- [ ] Email and other service records preserved.
- [ ] Registrar uses only the Cloudflare-assigned nameservers.
- [ ] DNSSEC validates, if enabled.
- [ ] GitHub Pages certificate is active and Enforce HTTPS is enabled.
- [ ] If using the Cloudflare proxy, Universal SSL is active and SSL mode is Full (strict).
- [ ] WAF rule tested on Proxied hostnames; normal site content still works.
Official documentation