How to Setup Custom Domain on Vercel with Cloudflare
ID | EN

How to Setup Custom Domain on Vercel with Cloudflare

Sunday, Dec 28, 2025

Have a project on Vercel but still using the *.vercel.app domain? It’s time to upgrade to a custom domain! In this tutorial, we’ll set up a custom domain using Cloudflare as DNS manager—a powerful combination for website performance and security.

Why Custom Domain?

Before we start, here’s why custom domains are important:

  • Professionalismprojectname.com is more credible than projectname.vercel.app
  • Branding — Your own domain = strong brand identity
  • SEO — Search engines favor custom domains
  • Professional email — Can set up hello@projectname.com
  • Full control — You own it, you control it

Step 1: Buy a Domain

First, you need a domain. Some recommended registrars:

Option 1: Namecheap

  • Affordable prices for popular TLDs (.com, .dev, .io)
  • Free WhoisGuard (privacy protection)
  • User-friendly interface

Option 2: Google Domains

  • Simple pricing, no hidden fees
  • Easy integration with Google services
  • Clean interface

Option 3: Cloudflare Registrar

  • At-cost pricing (no markup)
  • Directly integrated with Cloudflare DNS
  • No renewal price increases

Pro tip: If you buy a domain at Cloudflare Registrar, step 2 can be skipped since DNS is already automatically on Cloudflare.

Step 2: Setup Cloudflare DNS

Cloudflare will be our DNS manager. This makes websites faster and more secure.

2.1 Create Cloudflare Account

  1. Go to cloudflare.com
  2. Click Sign Up and create an account
  3. Choose the Free plan (sufficient for most use cases)

2.2 Add Domain

  1. In the dashboard, click Add a Site
  2. Enter your domain (example: projectname.com)
  3. Select Free plan, then click Continue
  4. Cloudflare will scan existing DNS records

2.3 Update Nameserver

Cloudflare will give you 2 nameservers, for example:

ada.ns.cloudflare.com
bob.ns.cloudflare.com

Go to the registrar where you bought your domain, then change the nameservers to those provided by Cloudflare.

At Namecheap:

  1. Login → Domain List
  2. Click Manage on your domain
  3. In the Nameservers section, select Custom DNS
  4. Enter Cloudflare nameservers

At Google Domains:

  1. Login → Select domain
  2. Click DNSCustom name servers
  3. Enter Cloudflare nameservers

DNS propagation usually takes 5-30 minutes, but can take up to 24 hours.

Step 3: Connect Domain to Vercel

Now we connect the domain to your Vercel project.

3.1 Add Domain in Vercel

  1. Open vercel.com and login
  2. Select the project you want to connect
  3. Go to SettingsDomains
  4. Click Add and enter your domain
  5. Vercel will display DNS instructions

3.2 Add DNS Records in Cloudflare

Vercel usually asks you to add one of these:

Option A - A Record (recommended for apex domain):

TypeNameContent
A@76.76.21.21

Option B - CNAME Record (for www or subdomain):

TypeNameContent
CNAMEwwwcname.vercel-dns.com

How to add in Cloudflare:

  1. Go to your domain dashboard
  2. Click the DNS tab → Records
  3. Click Add record
  4. Fill according to the table above
  5. Important: Set proxy status to DNS only (gray cloud icon)

3.3 Why Must Proxy Be Off?

Vercel already has its own CDN and SSL. If Cloudflare proxy is active (orange cloud), issues can occur:

  • SSL conflict
  • Redirect loop
  • Performance issues

So for the main domain, turn off Cloudflare proxy.

Step 4: SSL Configuration

Vercel automatically generates a free SSL certificate via Let’s Encrypt. But we need to ensure correct settings.

4.1 Vercel SSL

  1. In Vercel dashboard → SettingsDomains
  2. Make sure the domain has Valid Configuration status
  3. SSL certificate will auto-generate within a few minutes

4.2 Cloudflare SSL Settings

Since proxy is off, SSL is fully handled by Vercel. But if you enable proxy for other subdomains:

  1. Go to SSL/TLS in Cloudflare
  2. Set mode to Full (strict)
  3. This prevents mixed content and SSL errors

Step 5: Redirect www to non-www (or vice versa)

Choose one version as the primary domain. Usually developers prefer non-www (projectname.com).

5.1 Setup in Vercel

  1. In SettingsDomains, add both versions:
    • projectname.com
    • www.projectname.com
  2. Click one and select Set as Primary
  3. The other version will auto-redirect to primary

5.2 DNS Records for Both

In Cloudflare, add:

TypeNameContentProxy
A@76.76.21.21Off
CNAMEwwwcname.vercel-dns.comOff

Step 6: Setup Multiple Domains

Have more than one domain for one project? Easy.

6.1 Add All Domains in Vercel

  1. SettingsDomainsAdd
  2. Add each domain (example: projectname.io, projectname.dev)
  3. Set one as primary, the rest as redirects

6.2 DNS Setup for Each Domain

Repeat Step 3.2 for each domain in their respective Cloudflare.

Step 7: Setup Subdomain

Want to create blog.projectname.com or api.projectname.com? Here’s how.

7.1 In Vercel

You have 2 options:

Option A - Subdomain for the same project:

  1. SettingsDomainsAdd
  2. Enter blog.projectname.com
  3. Will point to the same project

Option B - Subdomain for different project:

  1. Open another project in Vercel
  2. Add subdomain in SettingsDomains

7.2 In Cloudflare

Add CNAME record:

TypeNameContentProxy
CNAMEblogcname.vercel-dns.comOff
CNAMEapicname.vercel-dns.comOff

Step 8: CDN Optimization

Although Vercel already has Edge Network, there are some additional optimizations.

8.1 Vercel Edge Network

Vercel projects are automatically deployed to global edge locations. For Asia, usually served from Singapore.

8.2 Enable Cloudflare Features (For Subdomains with Proxy On)

If there’s a subdomain with proxy active, enable:

  1. SpeedOptimization

    • Auto Minify (HTML, CSS, JS)
    • Brotli compression
  2. CachingConfiguration

    • Browser Cache TTL: 1 month
    • Set caching rules for static assets
  3. SpeedImage Optimization (Pro plan)

    • Polish: Lossless or Lossy
    • WebP conversion

8.3 Page Rules (Legacy) or Rules

Create rule for static assets:

URL: *projectname.com/assets/*
Setting: Cache Level = Cache Everything
Edge Cache TTL: 1 month

Step 9: Troubleshooting DNS Issues

Sometimes there are problems. Here’s how to debug.

9.1 “DNS_PROBE_FINISHED_NXDOMAIN”

Cause: DNS hasn’t propagated or record is wrong.

Solution:

  1. Check nameserver is updated at registrar
  2. Wait for propagation (check at whatsmydns.net)
  3. Verify DNS records in Cloudflare

9.2 “Too Many Redirects” or “ERR_TOO_MANY_REDIRECTS”

Cause: SSL conflict between Cloudflare and Vercel.

Solution:

  1. Turn off Cloudflare proxy (set to DNS only)
  2. Or set SSL mode to Full (strict)
  3. Clear browser cache and cookies

9.3 “Invalid Configuration” in Vercel

Cause: DNS records don’t match.

Solution:

  1. Make sure A record points to 76.76.21.21
  2. Or CNAME points to cname.vercel-dns.com
  3. Delete conflicting records
  4. Wait a few minutes and refresh Vercel dashboard

9.4 SSL Certificate Not Generated

Cause: DNS hasn’t propagated or CAA record blocking.

Solution:

  1. Make sure there’s no CAA record blocking Let’s Encrypt
  2. Or add CAA record that allows:
TypeNameContent
CAA@0 issue “letsencrypt.org”

9.5 Check DNS Propagation

Use these tools to verify:

  • whatsmydns.net — Global DNS propagation
  • dnschecker.org — Multiple DNS check
  • Terminal: dig projectname.com +short or nslookup projectname.com

Quick Checklist

Before going live, make sure:

  • Domain is purchased and active
  • Nameserver pointing to Cloudflare
  • DNS records added correctly
  • Cloudflare proxy off for main domain
  • Domain valid in Vercel dashboard
  • SSL certificate generated
  • www ↔ non-www redirect is set up
  • Test access from browser (clear cache first)

Conclusion

Setting up custom domain on Vercel with Cloudflare does require several steps, but the result is worth it. You get:

  • Professional custom domain
  • Powerful DNS management
  • Free and auto-renewing SSL
  • Global CDN for optimal performance
  • DDoS protection from Cloudflare (even with proxy off, basic protection still exists)

If you have questions or get stuck on any step, feel free to reach out. Happy deploying! 🚀