乐闻世界logo
搜索文章和话题

How to configure custom domains and SSL certificates on Vercel?

2月21日 16:28

How to configure custom domains and SSL certificates on Vercel?

Configuring custom domains and SSL certificates on Vercel is a straightforward process. Vercel provides automated SSL certificate management, making this process very convenient.

Custom Domain Configuration

1. Adding Custom Domains

Adding via Vercel Dashboard:

  1. Log in to Vercel Dashboard
  2. Select your project
  3. Go to "Settings" → "Domains"
  4. Click "Add Domain"
  5. Enter your domain (e.g., example.com or www.example.com)
  6. Choose domain type:
    • Production: For production environment
    • Preview: For preview deployments

Adding via Vercel CLI:

bash
# Add production domain vercel domains add example.com # Add preview domain vercel domains add preview.example.com --preview

2. Domain Types

Vercel supports the following domain types:

Root Domain:

  • example.com
  • Requires A record or CNAME alias record

Subdomain:

  • www.example.com
  • blog.example.com
  • api.example.com
  • Uses CNAME record

Wildcard Domain:

  • *.example.com
  • Matches all subdomains
  • Requires paid plan

3. DNS Configuration

Configuration Steps:

  1. Check DNS configuration requirements in Vercel Dashboard
  2. Log in to your domain registrar (e.g., GoDaddy, Namecheap, Cloudflare)
  3. Add appropriate DNS records based on type

A Record Configuration (for root domain):

shell
Type: A Name: @ Value: 76.76.21.21 TTL: 3600 (or default)

CNAME Record Configuration (for subdomain):

shell
Type: CNAME Name: www Value: cname.vercel-dns.com TTL: 3600 (or default)

Special Configuration with Cloudflare:

If you use Cloudflare as your DNS provider, note:

  1. Proxy Mode:

    • When Cloudflare proxy is enabled (orange cloud), Vercel may not correctly verify domain ownership
    • Recommend disabling proxy (gray cloud) first, wait for verification, then enable
  2. SSL Mode:

    • Set to "Full" or "Full (strict)"
    • Do not use "Flexible" mode

4. Domain Verification

Verification Process:

  1. After adding DNS records, Vercel automatically verifies domain configuration
  2. Verification typically takes a few minutes to a few hours (depending on DNS propagation)
  3. Once verified, domain status shows "Valid Configuration"

Verification Checks:

bash
# Check if DNS records are effective dig example.com # Check CNAME record dig www.example.com CNAME # Check DNS propagation nslookup example.com

SSL Certificate Configuration

1. Automatic SSL Certificates

Vercel uses Let's Encrypt to automatically provide SSL certificates for your domains:

Features:

  • Completely free
  • Automatic renewal
  • Supports HTTP/2 and HTTP/3
  • Automatic configuration

Certificate Types:

  • Single Domain Certificate: Protects a single domain
  • Wildcard Certificate: Protects main domain and all its subdomains (requires paid plan)

2. Automatic SSL Certificate Management

Automatic Issuance:

  • After domain verification passes, Vercel automatically issues SSL certificate
  • Usually completes within minutes
  • No manual operation required

Automatic Renewal:

  • Certificates automatically renew 30 days before expiration
  • No need to worry about certificate expiration
  • Fully automated

Certificate Monitoring:

  • Vercel continuously monitors certificate status
  • Automatically fixes issues when discovered
  • View certificate details in Dashboard

3. Force HTTPS

Automatic Redirect:

Vercel by default redirects all HTTP requests to HTTPS:

javascript
// Configure in vercel.json { "redirects": [ { "source": "/:path*", "has": [ { "type": "host", "value": "example.com" } ], "destination": "https://example.com/:path*", "permanent": true } ] }

HSTS Configuration:

javascript
{ "headers": [ { "source": "/(.*)", "headers": [ { "key": "Strict-Transport-Security", "value": "max-age=31536000; includeSubDomains" } ] } ] }

Advanced Configuration

1. Multiple Domain Configuration

Adding Multiple Domains:

  1. Add domains one by one in Domains settings
  2. Configure DNS records for each domain
  3. Wait for all domains to verify

Primary Domain Setting:

javascript
// Set primary domain in vercel.json { "name": "my-project", "alias": ["example.com", "www.example.com"] }

2. Environment-Specific Domains

Preview Environment Domain:

bash
# Add specific domain for preview deployments vercel domains add preview.example.com --preview

Development Environment Domain:

bash
# Add domain for development environment vercel domains add dev.example.com --dev

3. Custom 404 Page

Configure Custom 404 Page:

javascript
// Configure in vercel.json { "rewrites": [ { "source": "/404", "destination": "/custom-404.html" } ], "notFound": true }

Troubleshooting

1. Domain Verification Failed

Common Causes:

  • DNS record configuration error
  • DNS propagation not complete
  • Domain already used by another service
  • Cloudflare proxy mode issue

Solutions:

  1. Check if DNS records are correct
  2. Use DNS checking tools to verify records
  3. Wait for DNS propagation to complete (up to 48 hours)
  4. If using Cloudflare, temporarily disable proxy
bash
# Check DNS records dig example.com +short # Check WHOIS information whois example.com # Check DNS propagation dig example.com @8.8.8.8

2. SSL Certificate Issuance Failed

Common Causes:

  • Domain verification not passed
  • DNS record configuration error
  • Firewall blocking Let's Encrypt verification
  • Domain already used by another certificate

Solutions:

  1. Ensure domain verification passed
  2. Check DNS record configuration
  3. Check firewall settings
  4. Manually trigger certificate re-issuance in Dashboard

3. HTTPS Redirect Not Working

Checklist:

  1. Confirm SSL certificate has been issued
  2. Check redirect settings in Vercel configuration
  3. Clear browser cache
  4. Test in private mode

Best Practices

1. Domain Management

  • Use version control for domain configuration
  • Regularly check domain expiration dates
  • Set up auto-renewal for important domains
  • Keep backup of domain access credentials

2. SSL Security

  • Enable HSTS to force HTTPS
  • Regularly check SSL certificate status
  • Use strong passwords for domain accounts
  • Enable two-factor authentication

3. Monitoring and Alerts

  • Set up domain expiration reminders
  • Monitor SSL certificate status
  • Configure website availability monitoring
  • Set up error alerts

4. Performance Optimization

  • Use CDN to accelerate static resources
  • Enable HTTP/2 and HTTP/3
  • Optimize DNS resolution time
  • Use modern TLS versions

Frequently Asked Questions

Q1: Can I use free domains?

A: Yes, Vercel supports any legal domain, including free domains. However, it's recommended to use paid domains for better stability and support.

Q2: Is there a limit on SSL certificates?

A: In the free plan, you can add unlimited domains to each project, and each domain automatically receives an SSL certificate.

Q3: How do I migrate an existing domain to Vercel?

A:

  1. Add domain in Vercel
  2. Update DNS records to point to Vercel
  3. Wait for DNS propagation
  4. Verify configuration is correct

Q4: Can I use my own SSL certificate?

A: Vercel does not support uploading custom SSL certificates; you must use the automatically issued Let's Encrypt certificates from Vercel.

Q5: How long does domain configuration take to take effect?

A: Typically takes a few minutes to a few hours, up to 48 hours maximum (DNS propagation time).

Summary

Main advantages of configuring custom domains and SSL certificates on Vercel:

  1. Automated: SSL certificates automatically issued and renewed
  2. Simple: Intuitive configuration interface
  3. Free: Let's Encrypt SSL certificates completely free
  4. Secure: Automatic HTTPS redirect
  5. Reliable: 99.99% uptime guarantee

By following the steps and best practices above, you can easily configure custom domains and SSL certificates on Vercel, providing a secure, professional access experience for your website.

标签:Vercel