返回博客
五月 23, 2026指南

如何将域名指向您的 VPS

分步指南:DNS A 记录、www CNAME、验证及 Nginx 服务器块。

如何将域名指向您的 VPS

订购 VPS 后,最常见任务之一是将域名指向服务器 IP,让访客能打开网站。本指南说明在注册商处配置 DNS,并在 Hiddence VPS 上准备 Web 服务器。

所需条件

  • 已注册的域名(任意注册商)
  • Hiddence 客户区中的 VPS 公网 IP
  • 注册商 DNS 管理权限
  • 服务器上已安装 Nginx 或 Apache

步骤 1:创建 A 记录

登录注册商面板,打开 DNS 设置,添加将根域名指向 VPS IP 的 A 记录:

bash
Type: A
Host / Name: @  (or leave empty for root domain)
Value / Points to: YOUR_VPS_IP
TTL: 300–3600 (auto is fine)

步骤 2:配置 www 子域名

可为 www 再添加 A 记录,或使用指向根域名的 CNAME:

bash
Option A — A record:
Type: A
Host: www
Value: YOUR_VPS_IP

Option B — CNAME:
Type: CNAME
Host: www
Value: yourdomain.com

步骤 3:验证 DNS 传播

DNS 更改可能需要几分钟到 48 小时。检查域名是否解析到您的服务器:

bash
dig yourdomain.com +short
dig www.yourdomain.com +short

# Or use nslookup:
nslookup yourdomain.com

步骤 4:创建 Nginx 服务器块

DNS 指向 VPS 后,配置 Nginx 接受该域名的请求:

bash
sudo nano /etc/nginx/sites-available/yourdomain.com

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.com;
    index index.html index.php;
}

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

实用提示

  • 仅在了解代理/CDN 设置时使用 Cloudflare 等 DNS
  • DNS 生效后使用 Let's Encrypt(Certbot)安装 SSL
  • 迁移前降低 TTL 可加快 DNS 更新
  • 更改前备份旧 DNS 记录
  • 若运行邮件服务器,为邮件使用单独的 A 记录