Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Host Two Domains on One VPS Without a Control Panel

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to host two separate websites on a single virtual private server (VPS) using only the command line — no cPanel, Plesk, or similar control panel. You’ll set up Nginx (or Apache) to serve different content based on the domain name in the request, configure DNS, and secure both sites with SSL. By the end, both domains will resolve to your server’s IP and display their own site.

What You'll Need

  • A VPS running Linux (Ubuntu 22.04 or Debian 11/12 recommended) with root or sudo access.
  • Two domain names that you own and can modify DNS records for.
  • SSH client (Terminal on macOS/Linux, PuTTY on Windows).
  • Basic comfort with the command line.

Step-by-Step

  1. Connect to your VPS via SSH: ssh user@your_server_ip. Update the system: sudo apt update && sudo apt upgrade -y (Debian/Ubuntu).
  2. Install Nginx (or Apache if you prefer, but Nginx is lighter for this): sudo apt install nginx -y. Ensure it’s running: sudo systemctl status nginx.
  3. Create directory structure for each site. For example: sudo mkdir -p /var/www/domain1.com/html and sudo mkdir -p /var/www/domain2.com/html. Set ownership to your user: sudo chown -R $USER:$USER /var/www/domain1.com /var/www/domain2.com.
  4. Add a test index file for each site so you can verify later. Create /var/www/domain1.com/html/index.html with a simple <h1>Site 1</h1>, and similarly for domain2.
  5. Create Nginx server block configs. Copy the default config: sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/domain1.com. Edit it with sudo nano /etc/nginx/sites-available/domain1.com. Replace the server_name line with server_name domain1.com www.domain1.com; and set root /var/www/domain1.com/html;. Save and exit.
  6. Repeat for domain2: copy the default again to /etc/nginx/sites-available/domain2.com, edit similarly with server_name domain2.com www.domain2.com; and root /var/www/domain2.com/html;.
  7. Enable the sites by creating symlinks: sudo ln -s /etc/nginx/sites-available/domain1.com /etc/nginx/sites-enabled/ and same for domain2. Then remove the default site: sudo rm /etc/nginx/sites-enabled/default.
  8. Test Nginx configuration: sudo nginx -t. If it says “syntax is ok”, reload: sudo systemctl reload nginx.
  9. Point DNS records at your server’s IP. Log into your domain registrar’s DNS panel and create an A record for each domain (and www subdomain) pointing to your VPS IP address. Wait for propagation (can take minutes to hours).
  10. Verify both sites by visiting http://domain1.com and http://domain2.com in a browser. Each should show its own test page.
  11. Set up SSL certificates with Let’s Encrypt using Certbot: sudo apt install certbot python3-certbot-nginx -y. Then run sudo certbot --nginx -d domain1.com -d www.domain1.com and repeat for domain2. Follow the prompts to redirect HTTP to HTTPS.
  12. Test HTTPS: visit https://domain1.com and https://domain2.com. Both should show a padlock and your sites.

Common Mistakes

  • Forgetting to remove the default site – Nginx will still serve the default for any unmatched host, which can override your configs.
  • Wrong file permissions – If Nginx can’t read your web files, you’ll get a 403 Forbidden. Ensure the directories are readable (e.g., sudo chmod 755 /var/www/domain1.com).
  • DNS not propagated – You may see the old server or “site not found” if DNS hasn’t updated. Use dig domain1.com to check.
  • Missing www server_name – If you only set server_name domain1.com, visiting www.domain1.com will hit the default server. Add both.
  • Editing the wrong config file – Always edit files in sites-available and symlink to sites-enabled, not the other way around.

Tips

  • Use a separate Nginx server block for each domain, even if they share the same codebase – it makes maintenance easier.
  • Set up a firewall (UFW) to allow only SSH, HTTP, and HTTPS: sudo ufw allow OpenSSH && sudo ufw allow 'Nginx Full' && sudo ufw enable.
  • Automate SSL renewal: Certbot’s systemd timer usually handles it, but check with sudo systemctl status certbot.timer.
  • If you plan to host more sites later, consider using a naming convention like domain.com.conf for clarity.
  • Keep your server updated regularly to patch security vulnerabilities.

Troubleshooting

  • Site shows “Welcome to Nginx” – This means your server block isn’t being used. Check that the symlink exists and that the default site is removed. Run sudo nginx -T to see all active configs.
  • 404 Not Found – The server block is active but the root directory doesn’t have the expected index file. Check the path and file permissions.
  • 403 Forbidden – Nginx can’t access the directory. Fix permissions: sudo chmod 755 /var/www/domain1.com and ensure the HTML file is readable.
  • Both domains show the same site – Likely you copied the same config and forgot to change the root or server_name. Edit each config and reload.
  • SSL certificate fails – Ensure DNS has fully propagated before running Certbot. Also verify that port 80 is open in your firewall.
  • Server not reachable at all – Check that your VPS provider’s firewall allows HTTP/HTTPS traffic, and that Nginx is running.

Frequently Asked Questions

Can I host more than two domains this way?

Yes. Just repeat the steps: create a new directory, a new server block, enable it, and run Certbot for that domain. There’s no hard limit.

Do I need a separate IP address for each domain?

No. Nginx uses the Host header from the HTTP request to decide which site to serve, so one IP works for many domains.

What if I want to use Apache instead of Nginx?

The same concept applies. Apache uses virtual hosts. Install Apache, create config files in /etc/apache2/sites-available, enable them with a2ensite, and use Certbot with the Apache plugin.

How long does DNS propagation take?

Typically 1-2 hours, but it can take up to 48 hours depending on your registrar and TTL settings. You can check with dig or online DNS checkers.

Is it safe to use the same server for both domains?

Yes, as long as you keep the server updated and secure. If one site gets compromised, the other is at risk, so use strong passwords and consider isolating apps with separate user accounts or containers.

Can I run different web applications (e.g., WordPress and a Node.js app) on the same VPS?

Yes. You can configure Nginx as a reverse proxy for one domain (e.g., to a Node.js app on port 3000) while serving static files for the other. Each server block can have its own proxy settings.