域名绑定 #
域名概述 #
Vercel 支持为项目绑定自定义域名:
text
┌─────────────────────────────────────────┐
│ 域名类型 │
├─────────────────────────────────────────┤
│ 默认域名 → project.vercel.app │
│ 顶级域名 → example.com │
│ 子域名 → www.example.com │
│ 通配符域名 → *.example.com │
└─────────────────────────────────────────┘
添加域名 #
通过 Dashboard #
text
Project Settings → Domains → Add
text
┌─────────────────────────────────────────┐
│ Add Domain │
├─────────────────────────────────────────┤
│ Domain: [example.com ] │
│ │
│ [Add] │
└─────────────────────────────────────────┘
通过 CLI #
bash
vercel domains add example.com
text
> Success! Domain example.com added
批量添加 #
bash
vercel domains add example.com www.example.com api.example.com
域名验证 #
验证流程 #
text
┌──────────────────────────────────────────────────────┐
│ │
│ 添加域名 │
│ │ │
│ ▼ │
│ ┌─────────┐ │
│ │ DNS 验证 │ ← 添加 DNS 记录 │
│ └────┬────┘ │
│ │ │
│ ▼ │
│ ┌─────────┐ │
│ │ 验证成功 │ ← 域名生效 │
│ └────┬────┘ │
│ │ │
│ ▼ │
│ ┌─────────┐ │
│ │ SSL 配置 │ ← 自动配置 HTTPS │
│ └─────────┘ │
│ │
└──────────────────────────────────────────────────────┘
验证方法 #
方法一:添加 TXT 记录
text
类型: TXT
名称: _vercel
值: vc-domain-verify=xxx
方法二:添加文件验证
bash
# 在项目 public 目录创建验证文件
echo "verification-code" > public/.well-known/vercel.json
域名状态 #
| 状态 | 说明 | 操作 |
|---|---|---|
| Valid | 域名正常工作 | 无需操作 |
| Pending Verification | 等待验证 | 添加 DNS 记录 |
| Invalid Configuration | 配置错误 | 检查 DNS 设置 |
| SSL Pending | 等待证书 | 等待自动配置 |
DNS 配置 #
A 记录配置 #
用于顶级域名(如 example.com):
text
类型: A
名称: @
值: 76.76.21.21
TTL: 3600
CNAME 记录配置 #
用于子域名(如 www.example.com):
text
类型: CNAME
名称: www
值: cname.vercel-dns.com
TTL: 3600
不同域名服务商配置 #
Cloudflare #
text
DNS Records:
├── A @ 76.76.21.21 Proxied: No
└── CNAME www cname.vercel-dns.com Proxied: No
⚠️ 注意:确保 Cloudflare 代理(橙色云)已关闭
阿里云 #
text
DNS 设置:
├── A 记录 主机记录: @ 记录值: 76.76.21.21
└── CNAME 记录 主机记录: www 记录值: cname.vercel-dns.com
腾讯云 DNSPod #
text
记录管理:
├── A 记录 主机记录: @ 记录值: 76.76.21.21
└── CNAME 记录 主机记录: www 记录值: cname.vercel-dns.com
GoDaddy #
text
DNS Management:
├── A @ 76.76.21.21
└── CNAME www cname.vercel-dns.com
Namecheap #
text
Advanced DNS:
├── A Record @ 76.76.21.21
└── CNAME Record www cname.vercel-dns.com
域名重定向 #
www 重定向 #
text
Project Settings → Domains → Redirects
text
┌─────────────────────────────────────────┐
│ Redirect www to apex domain │
├─────────────────────────────────────────┤
│ www.example.com → example.com │
│ │
│ [Enable Redirect] │
└─────────────────────────────────────────┘
配置重定向 #
json
{
"redirects": [
{
"source": "www.example.com/:path*",
"destination": "https://example.com/:path*",
"permanent": true
}
]
}
多域名配置 #
添加多个域名 #
text
Project Settings → Domains
├── example.com (Production)
├── www.example.com (Redirects to example.com)
├── app.example.com (Production)
└── staging.example.com (Preview)
域名分配 #
text
┌─────────────────────────────────────────┐
│ Domain Assignment │
├─────────────────────────────────────────┤
│ Production Branch: main │
│ ├── example.com │
│ └── www.example.com │
│ │
│ Preview Branches: * │
│ └── staging.example.com │
└─────────────────────────────────────────┘
通配符域名 #
添加通配符域名 #
bash
vercel domains add '*.example.com'
DNS 配置 #
text
类型: CNAME
名称: *
值: cname.vercel-dns.com
使用场景 #
text
┌─────────────────────────────────────────┐
│ 通配符域名使用场景 │
├─────────────────────────────────────────┤
│ 多租户应用 → tenant1.example.com │
│ 子站点 → blog.example.com │
│ 区域站点 → cn.example.com │
└─────────────────────────────────────────┘
代码处理 #
javascript
export default function handler(req, res) {
const host = req.headers.host
const subdomain = host.split('.')[0]
res.json({ subdomain })
}
域名转移 #
从其他项目转移 #
text
Project Settings → Domains → Transfer
text
┌─────────────────────────────────────────┐
│ Transfer Domain │
├─────────────────────────────────────────┤
│ Domain: example.com │
│ From: old-project │
│ To: new-project │
│ │
│ [Transfer] │
└─────────────────────────────────────────┘
通过 CLI #
bash
vercel domains transfer example.com --to new-project
域名管理 #
查看域名列表 #
bash
vercel domains ls
text
Domains:
example.com Valid
www.example.com Redirects to example.com
app.example.com Valid
查看域名详情 #
bash
vercel domains inspect example.com
text
Domain: example.com
Status: Valid
Created: 2024-01-01
Expires: 2025-01-01
Nameservers:
- ns1.vercel-dns.com
- ns2.vercel-dns.com
删除域名 #
bash
vercel domains rm example.com
text
? Remove domain example.com from project? [y/N] y
> Success! Domain example.com removed
常见问题 #
DNS 未生效 #
text
检查项:
├── DNS 记录是否正确
├── TTL 是否过期
├── 是否关闭了代理(Cloudflare)
└── 等待 DNS 传播(最多 48 小时)
域名冲突 #
text
解决方案:
├── 从其他项目移除域名
├── 验证域名所有权
└── 联系 Vercel 支持
CNAME 无法用于顶级域名 #
text
解决方案:
├── 使用 A 记录指向 76.76.21.21
├── 或使用 ALIAS/ANAME 记录(如果支持)
└── 考虑使用 www 作为主域名
域名购买 #
Vercel 不提供域名注册服务,推荐以下域名注册商:
| 注册商 | 特点 |
|---|---|
| Namecheap | 价格实惠,界面友好 |
| Cloudflare | 成本价注册 |
| Google Domains | 简洁易用 |
| GoDaddy | 老牌注册商 |
| 阿里云 | 国内首选 |
| 腾讯云 | 国内备选 |
下一步 #
域名绑定完成后,接下来学习 DNS 配置详解 深入了解 DNS 配置!
最后更新:2026-03-28