Skip to content

Hosting multiple websites on one VPS with Nginx server blocks

By Onehost Team1 min read

One of the big advantages of a VPS is hosting multiple sites on a single server. Nginx makes this easy with server blocks (virtual hosts).

One file per site

Create a separate config in sites-available/ for each domain, each with its own server_name and root:

# /etc/nginx/sites-available/site1.com
server {
    listen 80;
    server_name site1.com www.site1.com;
    root /var/www/site1.com;
    index index.html;
}

Repeat for site2.com with its own root directory.

Enable them

sudo ln -s /etc/nginx/sites-available/site1.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/site2.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

Add HTTPS to each

sudo certbot --nginx -d site1.com -d site2.com

Nginx routes each request to the right site based on the domain. On a Onehost VPS with enough RAM and storage for your sites, you can comfortably host many sites on one server.

Put it into practice

Let our engineers set up, patch and monitor your web server.

Managed Linux VPS