How to Host Multiple Websites on a Single VPS with Nginx

If you are using a VPS, one of the smartest ways to save money and maximize resources is to host multiple websites on the same server.

Instead of buying separate hosting for each website, you can configure your VPS to serve multiple domains using Nginx.

In this guide, you’ll learn how to host multiple websites on a single VPS with Nginx, step by step.


How It Works

Nginx uses server blocks (similar to virtual hosts) to serve different websites based on domain names.

Example:

  • example1.com → Site 1
  • example2.com → Site 2

Requirements

  • VPS with Ubuntu
  • Nginx installed
  • Multiple domain names
  • Basic Linux knowledge

Step 1: Install Nginx

sudo apt update
sudo apt install nginx -y

Start service:

sudo systemctl start nginx

Step 2: Create Directory Structure

mkdir -p /var/www/site1
mkdir -p /var/www/site2

Step 3: Add Sample Content

echo "Site 1" > /var/www/site1/index.html
echo "Site 2" > /var/www/site2/index.html

Step 4: Set Permissions

chown -R www-data:www-data /var/www

Step 5: Create Server Block for Site 1

sudo nano /etc/nginx/sites-available/site1

Paste:

server {
    listen 80;
    server_name example1.com;

    root /var/www/site1;
    index index.html;
}

Step 6: Create Server Block for Site 2

server {
    listen 80;
    server_name example2.com;

    root /var/www/site2;
    index index.html;
}

Step 7: Enable Sites

ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/site2 /etc/nginx/sites-enabled/

Step 8: Test Configuration

nginx -t

Restart:

systemctl restart nginx

Step 9: Point Domains to VPS

Update DNS:

  • A record → VPS IP

Step 10: Add SSL (HTTPS)

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Run:

sudo certbot --nginx -d example1.com -d example2.com

Step 11: Verify Setup

Visit:


Advanced Setup

PHP Websites

Install PHP:

sudo apt install php-fpm

Reverse Proxy Apps

Proxy Node.js apps via Nginx.


Performance Optimization

  • Enable gzip
  • Use caching
  • Limit connections

Common Issues

Default Site Showing

Remove default config.

Domain Not Working

Check DNS propagation.


Best Practices

  • Separate directories
  • Use SSL for all sites
  • Monitor logs

Real-World Insight

Most VPS users waste money by:

👉 running only 1 site per VPS


FAQs

How many sites can I host?

Depends on VPS resources.

Is Nginx better than Apache?

Yes for performance.


Final Thoughts

Hosting multiple websites on a single VPS with Nginx is one of the most efficient and cost-effective ways to manage web hosting.


Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *