单域名+两组域名服务器(Glue Records)搭建多VPS站点求助
Alright, let's work through this step by step—you already got the glue records set up, which is a big win! Here's how to get those four domains hosted on your two VPSes without hitting more roadblocks:
Step 1: Finalize DNS Configuration
Glue records just lay the groundwork; now we need to tie your target domains to your VPS IPs properly:
- If
one-bar.com,two-bar.com,three-bar.com, andfour-bar.comare separately registered domains, head to each of their registrars and set their NS (Nameserver) records to point to your custom nameservers underfoo.com(e.g.,ns1.foo.comandns2.foo.com). The glue records you added earlier ensure DNS resolvers know the IPs for these foo.com nameservers, so this will resolve correctly. - Next, on your DNS server (I assume you're running one on vps1/vps2 for redundancy—if not, pick one VPS to host the primary DNS), create zone files for each domain:
- For
one-bar.comandtwo-bar.com: Add anArecord pointing to192.0.0.1(vps1's IP). You can also add aCNAMErecord forwww.one-bar.compointing toone-bar.comif you want the www subdomain to work. - For
three-bar.comandfour-bar.com: Add anArecord pointing to192.0.0.2(vps2's IP).
- For
- Verify DNS propagation with quick terminal checks:
Give it 10-30 minutes for records to propagate if they don't show up immediately.dig one-bar.com A dig ns one-bar.com
Step 2: Configure Web Servers on Each VPS
I'll use Nginx here (it's lightweight and widely supported)—the logic translates to Apache too, just adjust config file paths and syntax.
On vps1 (192.0.0.1)
- Install Nginx if you haven't already:
sudo apt update && sudo apt install nginx - Create a server block config for
one-bar.com:
Paste this basic config (tweak the root path or index files to match your project):sudo nano /etc/nginx/sites-available/one-bar.comserver { listen 80; server_name one-bar.com www.one-bar.com; root /var/www/one-bar.com/html; index index.html index.htm; location / { try_files $uri $uri/ =404; } } - Repeat the process for
two-bar.com—just update theserver_nameand root directory (e.g.,/var/www/two-bar.com/html). - Enable the server blocks by linking them to the
sites-enableddirectory:sudo ln -s /etc/nginx/sites-available/one-bar.com /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/two-bar.com /etc/nginx/sites-enabled/ - Test for config errors, then restart Nginx:
sudo nginx -t sudo systemctl restart nginx - Create website directories and add a test page:
Do the same forsudo mkdir -p /var/www/one-bar.com/html sudo chown -R $USER:$USER /var/www/one-bar.com/html echo "<h1>Hello from one-bar.com!</h1>" > /var/www/one-bar.com/html/index.htmltwo-bar.com.
On vps2 (192.0.0.2)
Follow the exact same steps as vps1, but for three-bar.com and four-bar.com. Since you're configuring this directly on vps2, the server blocks will automatically bind to its IP.
Step 3: Lock Down Firewalls & Add HTTPS
- Open ports 80 (HTTP) and 443 (HTTPS) on both VPSes to allow web traffic:
sudo ufw allow 'Nginx Full' - For HTTPS (highly recommended for security), use Certbot to get free SSL certificates:
Follow the prompts—Certbot will automatically update your Nginx configs to redirect HTTP to HTTPS.sudo apt install certbot python3-certbot-nginx sudo certbot --nginx
Quick Troubleshooting Tips
- If domains aren't loading, wait for full DNS propagation (can take up to 24 hours, but usually faster). Use
dig +trace one-bar.comto spot where resolution fails. - Check if Nginx is running:
sudo systemctl status nginx - Verify your VPS IPs are reachable:
curl http://192.0.0.1should load the default Nginx page or your test content.
内容的提问来源于stack exchange,提问作者Pankil Joshi
相关产品推荐
相关产品推荐

