Detailed Guide to Host Multiple Websites on 1 VPS with Docker and Nginx Proxy Manager
A detailed guide on hosting multiple websites on a single VPS using Docker and Nginx Proxy Manager, covering installation, configuration, management, and security.
Introduction
In today's digital era, hosting multiple websites on a single Virtual Private Server (VPS) is an efficient solution for cost and resource management. With the advancement of containerization technologies like Docker and proxy management tools such as Nginx Proxy Manager, deploying and managing multiple websites on a single server has become simpler and more secure than ever.
This guide will walk you through how to host multiple websites on one VPS using Docker and Nginx Proxy Manager. It is designed for both beginners and experienced DevOps professionals, with detailed steps for installation, configuration, management, and security.
Requirements and Preparation
Before you begin, ensure you have:
- A Linux-based VPS (Ubuntu 20.04/22.04 or Debian 11/12)
- Root or sudo user access
- A stable internet connection
- One or more domains (or local domains for testing environments)
Install Docker and Docker Compose
First, update your system and install Docker:
sudo apt update
sudo apt upgrade -y
sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
sudo systemctl enable docker
sudo systemctl start docker
Add Docker to your current user group to avoid using sudo:
sudo usermod -aG docker $USER
newgrp docker
Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Install Nginx Proxy Manager
We will use Docker Compose to deploy Nginx Proxy Manager:
Create a directory and configuration file:
mkdir -p ~/nginx-proxy-manager && cd ~/nginx-proxy-manager
Create the docker-compose.yml file:
version: '3.8'
services:
app:
image: 'nginxproxymanager/nginx-proxy-manager:latest'
container_name: nginx-proxy-manager
restart: unless-stopped
ports:
- '80:80'
- '443:443'
- '81:81'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
environment:
- DB_HOST=database
- DB_USER=nginxproxymanager
- DB_PASS=yourpassword
- DB_NAME=nginxproxymanager
- DB_PORT=3306
- NODE_ENV=production
- DEBUG=false
- VIRTUAL_HOST=yourdomain.com
- VIRTUAL_PORT=81
- [email protected]
- LETSENCRYPT_HOST=yourdomain.com
database:
image: 'mysql:8.0'
container_name: nginx-proxy-manager-db
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=yourrootpassword
- MYSQL_DATABASE=nginxproxymanager
- MYSQL_USER=nginxproxymanager
- MYSQL_PASSWORD=yourpassword
volumes:
- ./data/mysql:/var/lib/mysql
ports:
- '3306:3306'
Run the application:
docker-compose up -d
Access and Configure Nginx Proxy Manager
After starting, access the management interface at http://your-domain.com:81 or http://your-ip-address:81.
Log in with the default credentials:
- Username:
[email protected] - Password:
changeme
After logging in, configure websites by:
- Selecting Proxy Hosts → Add Proxy Host
- Filling in domain, internal port, and SSL options
- Selecting Let's Encrypt for automatic SSL issuance
- Saving and testing the connection
Host Multiple Websites with Docker
To host a website, create a Docker container running the application (e.g., WordPress, Node.js, etc.). Below is an example with a Node.js app:
# Create application directory
mkdir -p ~/my-node-app && cd ~/my-node-app
# Create package.json
cat < package.json
{
"name": "my-node-app",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js"
}
}
EOF
# Create server.js
cat < server.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from Node.js!');
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});
EOF
# Create Dockerfile
cat < Dockerfile
FROM node:18
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
EOF
# Build and run container
docker build -t my-node-app .
docker run -d --name my-node-app -p 3000:3000 my-node-app
In Nginx Proxy Manager, add a Proxy Host with:
- Domain:
node.mydomain.com - Forward Hostname/IP:
127.0.0.1 - Forward Port:
3000 - Select Let's Encrypt
Management and Security
To ensure security, perform the following steps:
- Change the default Nginx Proxy Manager password
- Keep Docker and Nginx Proxy Manager updated
- Set up a firewall (UFW) to open only necessary ports
- Implement logging and monitoring using tools like Grafana or Prometheus
Verification and Testing
After configuration, verify connectivity using:
curl -I http://node.mydomain.com
To test SSL:
openssl s_client -connect node.mydomain.com:443 > /dev/null 2>&1
Troubleshooting
- If access fails, check port forwarding and firewall settings
- Logs for Nginx Proxy Manager are located at
/data/logs - Run
docker-compose logs appto view errors - Ensure domain records point to the VPS IP address
References
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
