You are likely wasting money. If you are buying a new VPS for every small project or landing page, you are doing it wrong.

Nginx "Server Blocks" (similar to Virtual Hosts in Apache) act as a traffic cop. They check which domain name a visitor typed in (site1.com vs site2.com) and route them to the correct folder on your server. This allows you to host unlimited low-traffic sites on a single $5 VPS.

Prerequisites: A Joy Services VPS with Nginx installed and two domain names (A-Records) already pointing to your server's IP.

Step 1: Create the Directory Structure

First, we create the folders where your website files will live. We will do both sites at once to save time.

1. Create the directories:

Bash
root@joy:~# sudo mkdir -p /var/www/site1.com/html /var/www/site2.com/html

2. Fix Permissions:
By default, these folders are owned by root. We need to give your user permission to edit them.

Bash
root@joy:~# sudo chown -R $USER:$USER /var/www/site1.com/html sudo chown -R $USER:$USER /var/www/site2.com/html sudo chmod -R 755 /var/www

Step 2: Create Dummy Content

Create a simple file so we can verify the setup works.

Bash
root@joy:~# echo "" > /var/www/site1.com/html/index.html echo "" > /var/www/site2.com/html/index.html

Step 3: The Nginx Config

This is the most critical step. We need to tell Nginx how to handle the new domains.

1. Create the config for Site 1:

Bash
root@joy:~# sudo nano /etc/nginx/sites-available/site1.com

2. Paste the following configuration:

Nginx Config
server { listen 80; listen [::]:80; root /var/www/site1.com/html; index index.html index.htm index.nginx-debian.html; server_name site1.com www.site1.com; location / { try_files $uri $uri/ =404; } }

3. Repeat for Site 2:
Run sudo nano /etc/nginx/sites-available/site2.com and paste the code above again, but replace site1.com with site2.com.


Step 4: Enable and Test

Just creating the file doesn't turn it on. We must link it to the "sites-enabled" folder.

1. Create Symlinks:

Bash
root@joy:~# 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/

2. The "Bucket Size" Fix:
With multiple domains, Nginx's default memory for domain names is often too small. If you skip this, Nginx might crash.

root@joy:~# sudo nano /etc/nginx/nginx.conf

Find the line # server_names_hash_bucket_size 64; and remove the # symbol to uncomment it.

3. Test for Syntax Errors:

Bash
root@joy:~# sudo nginx -t
See an error? If it says "duplicate default server" or similar, check that you didn't accidentally copy the same config into both files.

4. Restart Nginx:

root@joy:~# sudo systemctl restart nginx

Step 5: Secure with SSL (Essential)

Your site is currently running on HTTP (Insecure). Modern browsers hate this. Let's fix it instantly with Certbot.

Bash
root@joy:~# sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d site1.com -d www.site1.com sudo certbot --nginx -d site2.com -d www.site2.com

Follow the prompts, select "2" to Redirect HTTP to HTTPS, and you are done. You now have two distinct, secure websites running on one Joy Services VPS.