Host Multiple Websites on One VPS with Docker and Nginx

Host Multiple Websites on One VPS with Docker and Nginx

If you’re wondering how to host multiple websites on one VPS with Docker and Nginx, the answer is simple: run each website inside its own Docker container and use Nginx as a reverse proxy to direct incoming traffic to the right container based on the domain name. This setup is secure, scalable, easy to manage, and allows you to host dozens of websites on a single VPS while keeping applications isolated from each other.

Whether you’re running WordPress, Laravel, Node.js, Python, PHP, or static websites, Docker and Nginx make managing multiple projects much easier than traditional server configurations.

In this blog, learn how to host multiple websites on one VPS using Docker and Nginx Reverse Proxy. Step-by-step guide covering setup, SSL certificates, security, scalability, and best practices.

Why Host Multiple Websites on One VPS?

A VPS provides dedicated resources without the high cost of a dedicated server. Instead of paying for multiple hosting accounts, you can deploy several websites on a single server.

Benefits include:

  • Lower hosting costs
  • Better resource utilization
  • Easier management
  • Complete root access
  • Independent applications
  • Simple backups
  • Easy scaling
  • Better security through container isolation

Why Use Docker?

Docker packages your application into a container along with all of its dependencies.

Each website runs independently.

For example:

  • Website A runs PHP 8.3
  • Website B runs Node.js 22
  • Website C runs Python Flask
  • Website D runs WordPress

None of these applications interfere with each other.

Advantages

  • Fast deployment
  • Isolated environments
  • Easy updates
  • Rollback support
  • Portability
  • Lower maintenance

Why Use Nginx?

Nginx is one of the fastest web servers available.

When combined with Docker, it becomes the gateway for all incoming traffic.

Nginx can:

  • Route requests by domain
  • Handle SSL certificates
  • Compress files
  • Cache content
  • Load balance applications
  • Protect against attacks

Architecture Overview

</> Code

Internet
│
▼
VPS Server
│
▼
Nginx
│
┌────┼─────────────┐
│ │ │ │
▼ ▼ ▼ ▼
Site1 Site2 Site3 Site4
Docker Docker Docker Docker

Only Nginx exposes ports 80 and 443.

Each website communicates internally with Nginx.

Requirements

Before starting, you’ll need:

A minimum of 2 GB of RAM is required (4 GB recommended)

Install Docker

Update your VPS first:

</> Bash
sudo apt update
sudo apt upgrade

Install Docker:

</> Bash
sudo apt install docker.io

Enable Docker:

</> Bash
sudo systemctl enable docker
sudo systemctl start docker

Verify installation:

</> Bash
docker --version

Install Docker Compose

Install Docker Compose:

</> Bash
sudo apt install docker-compose

Verify:

</> Bash
docker-compose version

Organize Your Project

Example directory structure:

</> Code
/home/websites/

├── site1
│ ├── docker-compose.yml
│ └── app
│
├── site2
│ ├── docker-compose.yml
│ └── app
│
├── site3
│ ├── docker-compose.yml
│ └── app
│
└── nginx
└── configs

Keeping projects separate makes management easier.

Example Docker Compose

Each website has its own compose file.

</> YAML
version: '3'

services:
web:
image: nginx
ports:
- "8081:80"

Another website:

</> YAML
ports:
- "8082:80"

Each container operates through its own internal port.

Configure Nginx Reverse Proxy

Example:

</> nginx
server {

server_name site1.com www.site1.com;

location / {
proxy_pass http://localhost:8081;
}

}

Second website:

</> nginx
server {

server_name site2.com www.site2.com;

location / {
proxy_pass http://localhost:8082;
}

}

Nginx automatically forwards visitors to the correct container.

Enable HTTPS

Install Certbot:

</> Bash
sudo apt install certbot python3-certbot-nginx

Generate SSL:

</> Bash
sudo certbot --nginx

Benefits:

  • HTTPS encryption
  • Automatic renewal
  • Better SEO
  • Browser trust
  • Improved security

DNS Configuration

Each domain should point to your VPS.

Example:

DomainA Record
site1.comVPS IP
site2.comVPS IP
site3.comVPS IP

Running Different Applications

Docker makes mixed environments easy.

Examples:

WebsiteTechnology
BlogWordPress
APINode.js
DashboardLaravel
Landing PageStatic HTML
StoreMagento
CRMPHP

Everything runs independently.

Resource Allocation

Docker allows limiting CPU and RAM.

Example:

</> YAML
deploy:
resources:
limits:
memory: 512M

This prevents one website from consuming all server resources.

Security Best Practices

Follow these recommendations:

  • Enable UFW firewall
  • Use SSH keys
  • Disable root login
  • Keep Docker updated
  • Update Nginx regularly
  • Install Fail2Ban
  • Use HTTPS only
  • Monitor logs
  • Restrict exposed ports
  • Use strong passwords

Performance Optimization

Improve VPS performance by:

  • Enabling Gzip
  • Using HTTP/2
  • Enabling browser caching
  • Compressing images
  • Using Redis cache
  • Optimizing databases
  • Using CDN
  • Monitoring memory usage
  • Cleaning unused Docker images

Backups

Regular backups are essential.

Back up:

  • Website files
  • Docker volumes
  • Databases
  • SSL certificates
  • Nginx configurations

Automate backups with cron jobs.

Updating Containers

Deploy updates easily:

</> Bash
docker-compose pull
docker-compose up -d

Downtime is minimal.

Monitoring Containers

Useful commands:

List running containers:

</> Bash
docker ps

View logs:

</> Bash
docker logs container_name

Monitor resources:

</> Bash
docker stats

Common Problems

Website Not Loading

Check:

  • Docker container running
  • DNS records
  • Nginx configuration
  • Firewall rules

SSL Errors

Verify:

  • Domain points to VPS
  • Port 443 is open
  • Certificate is valid

Port Conflicts

Avoid exposing multiple containers on the same port.

Example:

</> Code
8081
8082
8083
8084

Nginx handles routing externally.

Docker vs Traditional Hosting

FeatureDocker + NginxTraditional Hosting
Multiple AppsExcellentLimited
IsolationCompleteMinimal
DeploymentFastModerate
UpdatesEasyManual
PortabilityHighLow
RollbackSimpleDifficult
ScalabilityExcellentModerate
MaintenanceLowHigher

Best Practices

  • Use one Docker Compose file per website.
  • Keep applications isolated.
  • Store secrets securely using environment variables.
  • Regularly monitor your CPU, RAM, and disk usage.
  • Enable automatic SSL certificate renewal.
  • Remove unused Docker images and containers.
  • Keep Docker, Nginx, and your operating system updated.
  • Back up databases and persistent volumes frequently.
  • Test updates in a staging environment before deploying to production.

Conclusion

Host multiple websites on one VPS with Docker and Nginx is a modern, efficient, and cost-effective solution. Docker isolates each application into its own container, while Nginx acts as a powerful reverse proxy that routes traffic to the correct website and manages HTTPS with ease. This architecture simplifies deployments, improves security, and makes scaling your projects much easier than traditional hosting methods.

Whether you’re hosting personal blogs, business websites, APIs, or eCommerce stores, this setup gives you full control over your server while maximizing the value of your VPS. By following the best practices outlined above—using container isolation, enabling SSL, monitoring resources, and maintaining regular backups—you can build a reliable hosting environment capable of serving multiple websites with excellent performance and security.

Scroll to Top