DEV Community

Abdullah Sheikh
Abdullah Sheikh

Posted on

How to Host Multiple Websites on One VPS: A Step‑by‑Step Guide

Learn to configure Apache/Nginx, set up DNS, and isolate sites on a single VPS so you can launch and manage dozens of domains yourself

Before We Start: What You’ll Walk Away With

By the time you finish this guide you’ll be able to add a fresh domain to your VPS in under five minutes, just like ordering a coffee and getting it right away.

You’ll know exactly when to use a virtual host versus a container or a classic shared‑hosting setup—think of it as choosing between a single‑room apartment, a studio loft, or a full‑house rental depending on how much privacy each client needs.

Next, you’ll have a working Apache or Nginx configuration that serves any number of sites from the same server, similar to how Google Maps can display countless pins without slowing down.

Finally, you’ll walk away with a concise checklist that guarantees each site stays isolated and secure, like packing separate zip‑lock bags for different foods to avoid cross‑contamination.

  • Identify the right isolation method: virtual host, container, or shared hosting.

  • Set up the web server: edit apache2.conf or nginx.conf to add new host blocks.

  • Apply the security checklist: permissions, firewalls, SSL, and backups.

  • Virtual hosts: lightweight, perfect for dozens of low‑traffic sites.

  • Containers: add a full OS sandbox when a client needs custom software.

  • Shared hosting style: use when you want a quick, throw‑away test site.

Checklist:

  • Create a dedicated system user for each domain.

  • Set file ownership to that user.

  • Generate a free Let's Encrypt certificate.

  • Open only required ports in ufw.

With these tools in hand, hosting multiple websites on one VPS becomes a routine task, not a puzzle.

What Hosting Multiple Websites on One VPS Actually Is (No Jargon)

Hosting multiple websites on one VPS means you run several independent web‑applications on the same physical server, each pointed to its own folder by a virtual‑host configuration. The server’s resources—CPU, RAM, disk—are shared, but the sites stay isolated because the web server knows which files belong to which domain.

Think of a VPS as an office building and each website as a separate office. The building (the server) stays the same, but every office (site) has its own door (domain) and lock (config file). Visitors use the address on the door to get inside, and the security system makes sure they can’t wander into a neighboring office.

The 4 Mistakes Everyone Makes With Multi‑Site VPS Setups

Most people ruin their multi‑site VPS before they even finish the first deployment.

  • Overwriting the default virtual host – Think of it like changing the address on the front door of your house; every visitor now ends up at the wrong place. When you replace the default 000-default.conf with a new site’s config, the original site disappears. Keep the original file untouched and create a separate .conf for each domain.

  • Sharing one document root – Imagine stuffing every client’s luggage into the same suitcase; items collide and get lost. Using /var/www/html for all domains means index.html from one site overwrites another. Assign a unique folder, e.g., /var/www/site1, /var/www/site2, and point each virtual host there.

  • Skipping the reload/restart step – It’s like ordering food and never telling the kitchen it’s ready; the meal never arrives. After editing .conf files, run sudo systemctl reload nginx (or apache2) so the server reads the new settings.

Ignoring file‑system permissions – Think of leaving every drawer unlocked in a shared apartment; anyone can rummage through anyone else’s stuff. Set proper ownership and permissions, for example:

  • sudo chown -R www-data:www-data /var/www/site1
  • sudo chmod -R 750 /var/www/site1

This keeps each site’s files isolated and blocks cross‑site attacks.

Fix these four pitfalls and you’ll get a clean, secure environment for hosting multiple websites on one VPS.

How to Host Multiple Websites on One VPS: Step‑by‑Step

Refresh the system and pull in your web server. Think of it like updating the kitchen before cooking:

apt-get update && apt-get install nginx
Enter fullscreen mode Exit fullscreen mode

Lay out a separate folder for each site under /var/www. It’s like assigning a different drawer for every client’s paperwork:

mkdir -p /var/www/site1.com
Enter fullscreen mode Exit fullscreen mode

Set the folder ownership so the web server can read the files. This is the “hand‑off” to the kitchen staff:

chown -R www-data:www-data /var/www/site1.com
Enter fullscreen mode Exit fullscreen mode

Create a server block for the domain. Imagine giving the delivery driver a map that points straight to the right doorstep:

nano /etc/nginx/sites-available/site1.com
Enter fullscreen mode Exit fullscreen mode
server {
    listen 80;
    server_name site1.com www.site1.com;
    root /var/www/site1.com;
    index index.html;
}
Enter fullscreen mode Exit fullscreen mode

Then enable it:

ln -s /etc/nginx/sites-available/site1.com /etc/nginx/sites-enabled/
Enter fullscreen mode Exit fullscreen mode
  • Tell the world where to find the site. Sarah, a freelance photographer, adds an A‑record for photo‑studio.com that points to 203.0.113.45 in her registrar’s DNS panel.

Check the config for syntax errors and reload. It’s like tasting the sauce before serving:

nginx -t && systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Secure the site with a free certificate. Think of it as sealing the envelope with a tamper‑proof sticker:

certbot --nginx -d site1.com -d www.site1.com
Enter fullscreen mode Exit fullscreen mode

Optional: Add a firewall rule if you want traffic to a specific site to stay on its own lane. Example with ufw:

ufw allow from 203.0.113.0/24 to any port 80 comment 'site1.com traffic'
Enter fullscreen mode Exit fullscreen mode

A Real Example: Jane’s Portfolio & Client Blog on a Single VPS

Jane spins up a $10/mo VPS and wants her showcase at portfolio.janedoe.com and a client’s blog at blog.clientx.com on the same machine.

Log in and create two web roots:

sudo mkdir -p /var/www/portfolio.janedoe.com/public_html
sudo mkdir -p /var/www/blog.clientx.com/public_html
Enter fullscreen mode Exit fullscreen mode

Assign ownership to the www-data user:

sudo chown -R www-data:www-data /var/www/portfolio.janedoe.com
sudo chown -R www-data:www-data /var/www/blog.clientx.com
Enter fullscreen mode Exit fullscreen mode

Copy a simple index file into each folder (think of packing a suitcase with just the essentials):

Jane Doe – Designer
Welcome to my portfolio.

Client X Blog
Latest updates from Client X.
Enter fullscreen mode Exit fullscreen mode

Create two Nginx server blocks, one for each domain (like ordering two separate meals from the same kitchen):

sudo tee /etc/nginx/sites-available/portfolio.janedoe.com > /dev/null  /dev/null 
Enable the blocks and reload Nginx:

Enter fullscreen mode Exit fullscreen mode


bash
sudo ln -s /etc/nginx/sites-available/portfolio.janedoe.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/blog.clientx.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx


Obtain free SSL certificates with Certbot (think of wrapping each site in a safety blanket):

Enter fullscreen mode Exit fullscreen mode


bash
sudo certbot --nginx -d portfolio.janedoe.com -d www.portfolio.janedoe.com
sudo certbot --nginx -d blog.clientx.com -d www.blog.clientx.com




- Verify DNS points to the VPS IP for both domains (like setting the right address on a Google Maps pin).

- Test both URLs; each loads its own content over HTTPS and runs in its own directory.

Result: Jane’s portfolio and the client’s blog are live, each secured with HTTPS, and completely isolated from one another on the same VPS.

## The Tools That Make This Easier

First, grab the utilities that will keep your multi‑site VPS tidy and secure.

- Install **Certbot** and let it auto‑renew Let’s Encrypt certificates. Think of it as a coffee subscription that never runs out—once set, you never worry about it again.

- Deploy **Cockpit** for a graphical view of your virtual hosts. It’s like ordering food from a menu instead of typing every dish’s ingredients.

- Enable **Fail2Ban** to block repeated login attempts. Picture a bouncer that recognizes the same troublemaker and keeps them out without you lifting a finger.

- Configure **UFW** as the front‑door firewall. It’s the simple lock on your suitcase that you can set per site, so one domain’s rules don’t affect another.

- Set up **Git‑Deploy** to push code straight into `/var/www`. Imagine mailing a package that lands exactly where you need it, no unpacking required.

- **Certbot** – free client, runs `certbot renew` via cron, works with Nginx and Apache.

- **Cockpit** – web UI at `:9090`, edit `/etc/nginx/sites‑available` with a click.

- **Fail2Ban** – default jail for SSH, add `nginx‑auth` to protect each site’s login.

- **UFW** – simple commands like `ufw allow from 203.0.113.0/24 to any port 80` to isolate traffic.

- **Git‑Deploy** – drop a `post-receive` hook into `~/.ssh/authorized_keys` to auto‑copy a repo into the site folder.

With these tools in place, hosting multiple websites on one VPS becomes as painless as packing a suitcase with pre‑sorted compartments.

## Quick Reference: Multi‑Site VPS Cheat Sheet

Grab a pen and follow these bite‑size actions to keep every site tidy on a single VPS.

- Refresh the OS and pull in your web server: `apt update && apt install nginx` (or `apache2` if you prefer).

- Make a folder for each domain, e.g. `mkdir -p /var/www/example.com`. Think of it like assigning a separate drawer for each client’s paperwork.

- Give the web‑user ownership so the server can read and write: `chown -R www-data:www-data /var/www/example.com`.

- Create a server block (nginx) or virtual host (Apache) that points the domain to its folder. It’s the map that tells traffic which suitcase to open.

- Update DNS: set the **A‑record** of `example.com` to your VPS IP. *Maria, a freelance designer, does this in her domain registrar’s panel and the domain instantly knows where to go.*

- Validate the config – `nginx -t` or `apachectl configtest`. It’s the quick “does the recipe smell right?” check before you bake.

- Reload the service so changes take effect: `systemctl reload nginx` (or `apache2`).

- Secure the site with Let’s Encrypt: `certbot --nginx -d example.com`. One command, automatic renewals, no extra paperwork.

- **Optional**: tighten access with a firewall rule, e.g. `ufw allow from 203.0.113.0/24 to any port 22` for SSH.

- **Tip**: Keep a master `sites-available` list; copy it when you add a new site.

- **Tip**: Test each domain locally with `curl -I http://example.com` before DNS propagates.

Follow this cheat sheet and you’ll host multiple websites on one VPS without breaking a sweat.

## What to Do Next

Give it a quick test drive: add a second domain just like you did for the first, then pop it in the browser.

- **Easy** – Create a new `example2.com` config in `/etc/nginx/sites‑available`, link it, reload Nginx, and point the DNS to your VPS. It’s like ordering a second coffee after the first – same process, fresh result.

- **Medium** – Set up automated backups. A nightly `rsync` job or a Borg repository will copy each site’s `/var/www` folder to a safe location. Think of it as packing a spare suitcase for a trip; you’ll thank yourself if anything gets lost.

- **Hard** – Containerize every site with Docker Compose. Write a `docker‑compose.yml` that spins up an isolated Nginx, PHP, and DB container per domain while sharing the host’s network. This gives you the isolation of separate apartments in the same building.

- **Tip:** Keep a `backup.sh` script version‑controlled so you can recreate any site with one command.

- **Tip:** Use `docker‑compose logs` to troubleshoot container issues without digging through host logs.

Got a unique multi‑site setup or ran into a snag? Drop a comment below – I’d love to help!

---

---

## About the Author

**[Abdullah Sheikh](https://abdullah-sheikh.com/)** is the Founder & CEO at [Exteed](https://exteed.com/), where he leads a team of skilled developers specializing in [Web2](https://abdullah-sheikh.com/) and [Web3 applications](https://abdullah-sheikh.com/), [Custom Smart Contracts](https://abdullah-sheikh.com/), and [Blockchain solutions](https://abdullah-sheikh.com/).

With 6+ years of experience, Abdullah has built [CRMs](https://abdullah-sheikh.com/), [Crypto Wallets](https://abdullah-sheikh.com/), [DeFi Exchanges](https://abdullah-sheikh.com/), [E-Commerce Stores](https://abdullah-sheikh.com/), [HIPAA Compliant EMR Systems](https://abdullah-sheikh.com/), and [AI-powered systems](https://abdullah-sheikh.com/) that drive business efficiency and innovation.

His expertise spans [Blockchain](https://abdullah-sheikh.com/), [Crypto & Tokenomics](https://abdullah-sheikh.com/), [Artificial Intelligence](https://abdullah-sheikh.com/), and [Web Applications](https://abdullah-sheikh.com/); building reliable and smooth web apps that fit the client’s goals and requirements.

📧 [info@abdullah-sheikh.com](mailto:info@abdullah-sheikh.com) · 🔗 [LinkedIn](https://www.linkedin.com/in/-abdullah-sheikh/) · 🌐 [abdullah-sheikh.com](https://abdullah-sheikh.com/)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)