Host Multiple Domains on One VPS — A Clear, Step-by-Step Configuration Guide

Host Multiple Domains on One VPS — A Clear, Step-by-Step Configuration Guide

This clear, practical walkthrough shows how to host multiple domains on one VPS safely and efficiently, with hands-on examples for Nginx and Apache, TLS setup, and process isolation. Ideal for developers and small teams who want to consolidate sites, save costs, and keep each domain secure and performant.

Managing multiple domains on a single Virtual Private Server (VPS) is a common and cost-effective strategy for site owners, developers, and small enterprises. With the right configuration, one VPS can host several independent websites with separate document roots, SSL certificates, logging, and security boundaries. This guide provides a clear, step-by-step technical walkthrough to host multiple domains on one VPS, explaining the underlying principles, practical configuration examples (for both Nginx and Apache), security considerations, and purchasing recommendations.

How it works: underlying principles

At the core, hosting multiple domains on a single VPS relies on the web server’s ability to route incoming HTTP(S) requests to different virtual hosts based on the requested domain name (the Host header). Key elements include:

  • DNS: Each domain (example.com, example.net) points its A/AAAA records to the VPS public IP.
  • Web server virtual hosts: Nginx or Apache uses server blocks (Nginx) or VirtualHost containers (Apache) to map domain names to specific document roots and configurations.
  • Ports and IPs: All domains typically share the same IP and port 80/443; name-based virtual hosting distinguishes requests. Optionally, assign multiple IPs for strict isolation.
  • TLS/SSL: Certificates (Let’s Encrypt) are issued per domain or using SAN/wildcard certificates and deployed to the virtual host handling TLS termination.
  • Process isolation: Applications can run under different system users or containers (Docker/LXC) to increase security and separation.

Typical application scenarios

  • Multiple static sites for clients or company projects — low resource needs, simple Nginx configuration.
  • Multiple WordPress instances — each domain with its own database and PHP-FPM pool for performance isolation.
  • Microservices and API domains — use Nginx as a reverse proxy routing traffic to internal ports/containers.
  • Development/staging/prod environments — host separate domains like staging.example.com and app.example.com on the same VPS for cost efficiency.

Pros and cons: hosting many domains on one VPS

Before proceeding, consider the trade-offs:

  • Advantages
    • Cost-effective: one VPS payment for multiple sites.
    • Simpler network configuration and management compared to many small servers.
    • Centralized backup and monitoring.
  • Disadvantages
    • Single point of failure: if the VPS goes down, all domains go offline.
    • Resource contention: CPU, memory, disk I/O spikes on one site can impact others unless resources are limited per site.
    • Security risk: compromise of one site can escalate to others without proper isolation.

Before you start: prerequisites and planning

Prepare the following:

  • A VPS with a public IPv4 (and IPv6 if needed), SSH access, and sufficient RAM/CPU. For production use, consider SSD disk and a reliable provider. (For example, VPS.DO offers reliable USA-based VPS options.)
  • Root or sudo user access on the VPS.
  • Registered domain names with access to DNS management to point A/AAAA records.
  • Familiarity with Linux package manager (apt/yum) and basic shell commands.

Step-by-step configuration — common approach using Nginx + PHP-FPM

The following steps walk through DNS setup, Nginx virtual hosts, PHP-FPM pools for isolation, and TLS via Let’s Encrypt.

1. Configure DNS

  • For each domain, create an A record pointing to your VPS public IPv4. If you have IPv6, create an AAAA record as well.
  • Allow propagation (minutes to a few hours). You can verify using dig or nslookup: dig +short example.com.

2. Install base packages

On Debian/Ubuntu:

  • sudo apt update
  • sudo apt install nginx certbot python3-certbot-nginx php-fpm mysql-server

Adjust package names for RHEL/CentOS (nginx, certbot-nginx plugin, php-fpm, mariadb-server).

3. Create user and document root per domain

For better security, create a system user and separate directories.

  • sudo adduser –system –group –home /var/www/example_com example_com
  • sudo mkdir -p /var/www/example_com/public_html
  • sudo chown -R example_com:example_com /var/www/example_com
  • Place index.php or index.html in public_html for testing.

4. Configure PHP-FPM pools (optional but recommended)

Create a dedicated pool so each site uses its own PHP-FPM socket and user.

  • Copy default pool config: sudo cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/example_com.conf (adjust PHP version)
  • Edit example_com.conf:
    • Set [example_com] pool name
    • Set user = example_com and group = example_com
    • Set listen = /run/php/php7.4-fpm-example_com.sock
  • Restart PHP-FPM: sudo systemctl restart php7.4-fpm

5. Create Nginx server block (virtual host)

Example Nginx configuration for example.com:

  • Create file: /etc/nginx/sites-available/example.com
  • Basic content (summary):

server {
  listen 80;
  server_name example.com www.example.com;
  root /var/www/example_com/public_html;
  index index.php index.html;
  access_log /var/log/nginx/example.com.access.log;
  error_log /var/log/nginx/example.com.error.log;
  location / { try_files $uri $uri/ /index.php?$args; }
  location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm-example_com.sock; }
  location ~ /.ht { deny all; }
}

  • Enable site: sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
  • Test and reload: sudo nginx -t && sudo systemctl reload nginx

6. Obtain TLS with Let’s Encrypt

  • Use Certbot’s Nginx plugin to automatically configure SSL:
  • sudo certbot --nginx -d example.com -d www.example.com
  • Certbot will obtain certificates and update the Nginx block to listen on 443 with the new certificate files. It also sets up automatic renewal via systemd timer or cron.
  • For multiple domains, repeat certbot per server block or use SAN certificates when appropriate.

7. Repeat for additional domains

Follow steps 3–6 for each domain, creating unique users, PHP-FPM pools, document roots, and Nginx server blocks. This ensures separation of files, processes, and logs.

Advanced options and security hardening

Resource limits and process isolation

  • Use PHP-FPM pool settings to limit pm.max_children, memory consumption, and process timeouts.
  • Set ulimits and systemd resource controls for services when appropriate.
  • Consider using containerization (Docker) to isolate apps further. A reverse proxy (Nginx) on the host can route to container ports.

Firewall and SSH

  • Use a firewall (ufw/iptables/firewalld) to allow only required ports: 22 (SSH), 80, 443. For IPv6, ensure firewall rules cover ::/0 appropriately.
  • Harden SSH: disable password auth, use key-based authentication, change default port if useful, and enable fail2ban for brute-force protection.

Monitoring, logs and backups

  • Centralize logs (ELK, Graylog) or use logrotate to prevent disk exhaustion.
  • Monitor resource usage (Prometheus, Netdata). Set alerts on CPU, memory, disk I/O, and process failures.
  • Automate backups of /var/www and databases. Store backups remotely and test restores periodically.

Security best practices

  • Run web applications with the least privilege (separate user accounts).
  • Keep the system and packages updated. Enable unattended security updates for critical patches when appropriate.
  • Limit writable directories and use proper file permissions: web root files 644, directories 755, and directories owned by their site user.
  • Use web application firewalls (ModSecurity with OWASP rules or Nginx WAF) for additional protection.

Apache alternative: name-based VirtualHosts

Apache uses <VirtualHost *:80> blocks keyed by ServerName/ServerAlias. Steps mirror Nginx: set DNS A records, create document roots, configure VirtualHost files in /etc/apache2/sites-available/, enable sites with a2ensite, reload Apache, and obtain TLS via certbot --apache. For PHP, Apache MPM + PHP-FPM or mod_php are options — PHP-FPM with distinct pools offers better isolation.

Choosing resources and VPS sizing

Sizing depends on traffic, application type, and expected growth. As a rule of thumb:

  • Static sites and low-traffic blogs: 1–2 vCPU and 1–2 GB RAM.
  • Multiple WordPress sites with occasional traffic: 2–4 vCPU and 4–8 GB RAM.
  • High-traffic or transactional sites: scale to dedicated resources or split services across VPSs (database on a separate instance).

Also consider disk I/O performance (choose SSD), network bandwidth limits, and snapshot/backup options from your provider.

When to consider separate VPS instances

  • High availability requirements where a single point of failure is unacceptable.
  • Strict compliance or security boundaries requiring physical isolation.
  • Sites with large or bursty resource usage that can impact co-hosted sites.

Summary

Hosting multiple domains on a single VPS is practical and efficient when you apply careful configuration and security practices. The key steps include proper DNS setup, creating distinct document roots and system users, configuring virtual hosts in Nginx or Apache, using dedicated PHP-FPM pools if running PHP applications, securing the server (firewall, SSH hardening, fail2ban), and obtaining TLS certificates with Let’s Encrypt. Monitor resource usage and logs, automate backups, and evaluate whether containerization or splitting services across multiple VPSs is needed based on your risk tolerance and performance requirements.

If you’re evaluating VPS providers for this setup, consider options with reliable network performance, SSD storage, and flexible plans. For U.S.-based hosting, you can review offerings like the USA VPS plans at VPS.DO — USA VPS which provide a range of configurations suitable for multi-domain hosting scenarios.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!