Overview
Cloudflare Pages makes it easy to use a custom domain for your Astro portfolio. You can connect a domain registered with any provider, and Cloudflare will automatically provision SSL certificates and handle DNS configuration. The production site useslewiskori.com as configured in astro.config.mjs:11-17:
The
site configuration is used for generating absolute URLs in sitemaps, RSS feeds, and canonical links.Prerequisites
Before you begin, ensure you have:- A deployed Cloudflare Pages project
- A registered domain name (can be from any registrar)
- Access to your domain’s DNS settings
Setup Options
You can connect a custom domain in two ways:- Domain on Cloudflare (Recommended) - Transfer or use an existing domain managed by Cloudflare
- External Domain - Point an external domain to Cloudflare Pages using CNAME records
Option 1: Domain on Cloudflare (Recommended)
Add Domain to Cloudflare
If your domain isn’t already on Cloudflare:
- Log in to the Cloudflare Dashboard
- Click Add a Site
- Enter your domain name (e.g.,
example.com) - Select a plan (Free plan works great)
- Cloudflare will scan your existing DNS records
You don’t need to transfer your domain registration. You only need to point your domain’s nameservers to Cloudflare.
Update Nameservers
At your domain registrar (GoDaddy, Namecheap, etc.):
- Find the nameserver settings
- Replace existing nameservers with Cloudflare’s nameservers:
ns1.cloudflare.comns2.cloudflare.com(Exact nameservers will be shown in your Cloudflare dashboard)
- Save changes
Connect to Pages Project
Once your domain is active on Cloudflare:
- Navigate to Pages > Your project
- Go to Custom domains tab
- Click Set up a custom domain
- Enter your domain (e.g.,
lewiskori.comorwww.lewiskori.com) - Click Continue
- Create DNS records
- Provision SSL certificate
- Configure CDN routing
Configure Apex and WWW
Decide on your preferred domain structure:Option A: Use apex domain (
example.com)- Add
example.comas custom domain - Optionally add
www.example.comwith redirect to apex
www.example.com)- Add
www.example.comas custom domain - Add
example.comwith redirect to www
The project’s site URL is set to
https://lewiskori.com (apex domain). Update this in astro.config.mjs if using a different structure.Option 2: External Domain
If you prefer to keep your domain with your current registrar:Add Custom Domain in Pages
- Navigate to Pages > Your project > Custom domains
- Click Set up a custom domain
- Enter your domain name
- Cloudflare will provide CNAME target
Add CNAME Record
At your domain registrar’s DNS settings:
| Type | Name | Target |
|---|---|---|
CNAME | @ or www | [project-name].pages.dev |
Some registrars don’t support CNAME records for apex domains (
@). In this case, use www subdomain or consider moving DNS to Cloudflare.Wait for DNS Propagation
DNS changes typically propagate within:
- 15 minutes to 1 hour: Most changes
- Up to 24-48 hours: Maximum wait time
DNS Configuration Details
Recommended DNS Records
For a complete setup with apex and www:| Type | Name | Target | Proxy Status |
|---|---|---|---|
CNAME | @ | [project-name].pages.dev | Proxied (orange cloud) |
CNAME | www | [project-name].pages.dev | Proxied (orange cloud) |
Cloudflare automatically handles these when you add a custom domain to Pages.
Additional Subdomains
To add subdomains (e.g.,blog.example.com):
- In Cloudflare Pages, add the subdomain as a custom domain
- Cloudflare creates the necessary DNS record automatically
- SSL certificate covers the subdomain
SSL/TLS Configuration
Cloudflare Pages automatically provides:- Free SSL Certificate: Universal SSL for your custom domain
- Automatic Renewal: Certificates renew automatically before expiration
- TLS 1.3 Support: Modern encryption protocols
- HTTP/2 and HTTP/3: Fast, efficient protocols enabled by default
SSL Settings
Verify SSL Mode
In Cloudflare Dashboard:
- Go to SSL/TLS > Overview
- Ensure mode is set to Full or Full (strict)
Cloudflare Pages uses edge certificates, so Full (strict) mode works seamlessly.
Enable Always Use HTTPS
Force all traffic to HTTPS:
- Navigate to SSL/TLS > Edge Certificates
- Enable Always Use HTTPS
- All HTTP requests will redirect to HTTPS automatically
Updating Site Configuration
After connecting your custom domain, update the Astro configuration:Rebuild and Deploy
Commit and push your changes:Cloudflare Pages will automatically rebuild with the new configuration.
Verify Sitemap and SEO
After deployment, check:
https://yourdomain.com/sitemap-index.xml- Should use your custom domain- Page canonical URLs - Should reference custom domain
- Open Graph tags - Should use custom domain for images and URLs
The sitemap configuration in
astro.config.mjs:64-106 automatically uses the site value for generating URLs.Domain Management
Multiple Domains
You can add multiple custom domains to one project:- Production domain: Main domain (e.g.,
lewiskori.com) - Alternate domains: Additional domains that redirect to main
- Localized domains: Country-specific domains (e.g.,
lewiskori.co.uk)
Domain Redirects
Set up redirects in Cloudflare:- Bulk Redirects: Redirect multiple patterns at once
- Page Rules: Create custom redirect rules (3 rules on free plan)
- Transform Rules: Modern way to handle redirects
www to apex domain automatically with Cloudflare’s redirect rules.
Troubleshooting
Domain Not Working
Check DNS Propagation
Use DNS Checker to verify your domain resolves globally:
Verify CNAME Target
Ensure CNAME points to correct target:
- Should be
[project-name].pages.dev - Check in Cloudflare Pages dashboard for exact value
SSL Certificate Issues
- Certificate Pending: Wait 1-2 minutes for provisioning
- Certificate Error: Verify DNS is pointing to Cloudflare
- Mixed Content: Ensure all assets load over HTTPS
Redirect Loops
If you experience infinite redirects:- Check SSL/TLS mode is Full or Full (strict)
- Disable “Always Use HTTPS” temporarily to test
- Clear browser cache and cookies
- Check for conflicting redirect rules
Performance Optimization
With your custom domain on Cloudflare:- Global CDN: Content cached at 300+ locations worldwide
- HTTP/3: Enabled automatically for improved performance
- Brotli Compression: Automatic compression for faster loading
- Smart Routing: Argo Smart Routing for optimal paths (paid feature)
Your Astro portfolio is already optimized with static assets in
dist/, which are automatically cached by Cloudflare’s CDN.Next Steps
Environment Variables
Configure API keys for your custom domain
Cloudflare Pages
Learn more about Cloudflare Pages deployment