Connect Your Custom Domain to Cloudflare Pages
Step-by-step guide to connecting your domain to Cloudflare Pages.
You've built your site. Deployed it to Cloudflare Pages. Now you want your custom domain to point to it. Should be simple, right?
Except you hit a 522 error. Or your domain shows a parking page. Or it just times out. DNS is working but the site isn't loading.
Here's the complete guide to connecting your custom domain to Cloudflare Pages, based on real troubleshooting. No fluff, just the exact steps.
Prerequisites
Before starting, you need:
- A domain registered (anywhere: Namecheap, GoDaddy, Spaceship, etc.)
- A deployed Cloudflare Pages project
- Access to your domain registrar's DNS settings
The Two-Part Setup
Most guides skip this, but there are two separate things you must configure:
- DNS Records - Point your domain to Cloudflare Pages
- Pages Custom Domain - Tell Cloudflare Pages to accept traffic from your domain
Missing either one causes errors. Let's do both.
Option 1: Full Cloudflare (Recommended)
This is the cleanest approach. Transfer DNS management to Cloudflare entirely.
Step 1: Add Domain to Cloudflare
- Go to Cloudflare Dashboard
- Click "Add a site" in the top right
- Enter your domain:
yourdomain.com - Click "Add site"
- Select "Free" plan
- Click "Continue"
Cloudflare will scan your existing DNS records.
Step 2: Review and Import DNS Records
Cloudflare shows your existing DNS records. Review them:
- If you had email (MX records), they'll be imported
- If you had www subdomain, it'll be there
- Old A/CNAME records will show up
Click "Continue" to import them. Don't worry, we'll update them next.
Step 3: Get Your Cloudflare Nameservers
Cloudflare assigns you two nameservers. They look like:
amber.ns.cloudflare.com greg.ns.cloudflare.com
Copy these. You'll need them next.
Step 4: Update Nameservers at Your Registrar
Go to wherever you bought your domain (Namecheap, GoDaddy, Spaceship, etc.):
- Log in to your registrar
- Find your domain
- Look for "Nameservers" or "DNS" settings
- Change from registrar's nameservers to "Custom nameservers"
- Paste the Cloudflare nameservers
- Save
This can take 15 minutes to 48 hours to propagate. Usually it's under an hour.
Step 5: Wait for Activation
Back in Cloudflare:
- Click "Done, check nameservers"
- You'll see a pending status
- Check your email - Cloudflare sends confirmation when it's active
- Or refresh the dashboard - it'll show a green banner when ready
Step 6: Configure DNS Records
Once active, go to your domain in Cloudflare → DNS → Records:
Delete any old A or CNAME records for your root domain and www.
Add these two records:
For root domain (yourdomain.com):
Type: CNAME Name: yourdomain.com (or @) Target: your-project.pages.dev Proxy status: Proxied (orange cloud) TTL: Auto
For www subdomain:
Type: CNAME Name: www Target: your-project.pages.dev Proxy status: Proxied (orange cloud) TTL: Auto
Click "Save".
Replace your-project.pages.dev with your actual Pages URL (like solobuilder-dev.pages.dev).
Step 7: Add Custom Domain to Pages Project
This is the step most people miss.
DNS points to Cloudflare, but Pages doesn't know to serve your site yet.
- Go to Workers & Pages (left sidebar)
- Click your project name
- Click "Custom domains" tab
- Click "Set up a custom domain"
- Enter:
yourdomain.com - Click "Continue"
- Cloudflare checks DNS and says "DNS records found" ✅
- Click "Activate domain"
Repeat for www:
- Click "Set up a custom domain" again
- Enter:
www.yourdomain.com - "Continue" → "Activate domain"
Step 8: Verify It Works
Wait 2-5 minutes, then visit:
https://yourdomain.comhttps://www.yourdomain.com
Both should load your site with automatic HTTPS!
Option 2: External DNS (Alternative)
If you want to keep DNS at your registrar (not recommended, but possible):
- Don't change nameservers
- At your registrar, add these DNS records:
For root domain:
Type: CNAME Name: @ (or yourdomain.com) Target: your-project.pages.dev
For www:
Type: CNAME Name: www Target: your-project.pages.dev
- Then follow Step 7 above to add custom domains in Pages project
Note: You won't get Cloudflare's CDN, caching, or protection this way. Not recommended.
Common Errors and Fixes
Error 522: Connection Timed Out
Cause: DNS points to Cloudflare, but Pages doesn't know to serve your site.
Fix: Add the custom domain in Workers & Pages → Your Project → Custom domains.
Domain Shows Parking Page
Cause: Nameservers not updated yet, or DNS records not configured.
Fix: Check nameserver propagation at whatsmydns.net. Wait longer or verify nameservers are correct.
"Too Many Redirects"
Cause: SSL/TLS encryption mode is wrong.
Fix: Go to SSL/TLS → Overview → Set to "Full" or "Full (strict)".
www Works But Root Doesn't (or Vice Versa)
Cause: Only added one custom domain to Pages.
Fix: Add both yourdomain.com AND www.yourdomain.com in Custom domains.
DNS_PROBE_FINISHED_NXDOMAIN
Cause: DNS records aren't propagated or are wrong.
Fix: Check your DNS records in Cloudflare. Verify CNAME targets are correct. Wait for propagation.
Email Security (Prevent Spoofing)
If you're not using email on this domain, prevent spammers from spoofing it:
Add SPF record:
Type: TXT Name: @ Content: v=spf1 -all
Add DMARC record:
Type: TXT Name: _dmarc Content: v=DMARC1; p=reject; sp=reject; adkim=s; aspf=s;
This tells email servers: "Don't accept emails from this domain - I don't send email here."
Verify Everything Works
Use these tools to confirm your setup:
DNS Propagation:
SSL Certificate:
- Visit your site - should show 🔒 in browser
Performance:
Headers (check if proxied):
Why Use Cloudflare for DNS?
You could keep DNS at your registrar and just point to Pages. But here's why full Cloudflare is better:
Performance:
- Global CDN (your site loads fast everywhere)
- Automatic caching
- Smart routing
Security:
- DDoS protection
- Free SSL certificates
- Bot filtering
- WAF (Web Application Firewall)
Features:
- Email routing (forward emails for free)
- Page Rules (redirects, caching rules)
- Workers (serverless functions)
- Analytics (privacy-friendly, built-in)
Cost:
- All free for most sites
- No bandwidth limits
- Unlimited DNS queries
The Checklist
Bookmark this for next time:
- [ ] Add domain to Cloudflare (if using full Cloudflare)
- [ ] Update nameservers at registrar
- [ ] Wait for activation (check email)
- [ ] Add CNAME records in Cloudflare DNS
- [ ] Add custom domains in Pages project (both root and www)
- [ ] Verify both URLs load with HTTPS
- [ ] Add email security records (SPF/DMARC)
- [ ] Test with whatsmydns.net
Troubleshooting Checklist
Site not loading? Run through this:
- DNS propagation complete? Check whatsmydns.net
- Nameservers correct in registrar? Verify they match Cloudflare's
- DNS records correct? CNAME pointing to
your-project.pages.dev - Custom domain added in Pages? Check Workers & Pages → Custom domains
- Both root and www added? Need both if you want both to work
- SSL mode correct? Should be "Full" or "Full (strict)"
- Still broken? Clear browser cache or try incognito mode
Real-World Timeline
Realistic deployment timeline:
- Nameserver update: 15 min - 24 hours (usually 30-60 min)
- DNS record propagation: 1-5 minutes
- SSL certificate provisioning: 1-2 minutes
- Total: 30 minutes to 24 hours (usually under 1 hour)
Don't panic if it's not instant. DNS takes time.
Tips for Solo Builders
Start with Cloudflare Pages subdomain first: Before buying a domain, deploy to your-project.pages.dev. Make sure the site works. Then add the custom domain. Easier to debug when you know the site itself works.
Use Full Cloudflare: Don't half-ass it by keeping DNS at your registrar. Move it all to Cloudflare. You get better performance, security, and troubleshooting is simpler.
Don't skip www: Add both yourdomain.com and www.yourdomain.com as custom domains. Users type both. Both should work.
Test in incognito: Your browser caches DNS aggressively. When testing, use incognito mode or a different browser.
Bookmark whatsmydns.net: Best tool for checking if DNS changes have propagated globally.
The Most Common Mistake
Adding DNS records but forgetting to add the custom domain in the Pages project.
Your DNS can be perfect, but if Pages doesn't know to serve your site for that domain, you'll get a 522 error.
Always do both:
- DNS records in Cloudflare DNS
- Custom domain in Pages project settings
What If You Already Have Email?
Moving nameservers to Cloudflare won't break email if you import the MX records.
When Cloudflare scans your domain, it imports existing MX records. Just make sure they're there before confirming.
Or manually add them:
Type: MX Name: @ Mail server: [your email provider's server] Priority: [usually 10]
Check your email provider's docs for exact MX records.
Next Steps After Setup
Once your domain works:
- Submit sitemap to Google Search Console
- Set up analytics (Cloudflare Analytics is free and built-in)
- Configure redirects (e.g., www → non-www or vice versa)
- Set up email routing (forward emails to your personal address)
- Add monitoring (UptimeRobot, Checkly, or Cloudflare's built-in)
The Bottom Line
Connecting a custom domain to Cloudflare Pages is a two-step process that most guides oversimplify:
- Point DNS to Pages (via CNAME records)
- Tell Pages to accept the domain (Custom domains in project settings)
Do both, wait for DNS propagation, and you're live.
The confusion comes from older hosting where you just update DNS and you're done. With Cloudflare Pages, you explicitly add domains to projects. Once you know this, it's straightforward.
Now go ship your site on your own domain. You've got this.