Add Additional Domains to Nginx Vhost: A Step-by-Step Guide

Managing multiple domains on a single server can be a challenging task. Nginx, a powerful web server software, offers a convenient solution: virtual hosts (vhosts). In this tutorial, we’ll guide you through the process of adding additional domains to Nginx as a vhost entry, simplifying your server management and streamlining your configurations.


Before proceeding, make sure you have the following in place:

  1. An Nginx server installed and running on a Linux-based system. If you need help with the installation, follow the official Nginx installation guide.
  2. Root or sudo access to your server.
  3. At least one domain name with its DNS records pointing to your server’s IP address.

Step 1: Create Directories for Additional Domains

For each new domain you wish to add to your Nginx vhost, create a directory to store its files. Replace with your actual domain name:

sudo mkdir -p /var/www/

Next, adjust the ownership and permissions for the newly created directory:

sudo chown -R $USER:$USER /var/www/
sudo chmod -R 755 /var/www/

Step 2: Create a Sample Index Page

Create a sample index.html file for the new domain:

nano /var/www/

Add some basic HTML content to the file:

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <title>Welcome to</title>
    <h1>Success! is now hosted on Nginx.</h1>

Save and close the file.

Step 3: Configure Nginx Server Block

Create a new Nginx server block configuration file for the additional domain:

sudo nano /etc/nginx/sites-available/

Add the following configuration, replacing with your actual domain name:

server {
    listen 80;

    root /var/www/;
    index index.html;

    location / {
        try_files $uri $uri/ =404;

Save and close the file.

Step 4: Enable the New Server Block

Create a symbolic link to the newly created server block configuration file:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Verify the Nginx configuration for any syntax errors:

sudo nginx -t

If there are no errors, reload Nginx to apply the changes:

sudo systemctl reload nginx

Step 5: Test Your New Domain

Visit your new domain in a web browser, and you should see the sample index page you created earlier. If you see the “Success!” message, you’ve successfully added the additional domain Nginx. By following this step-by-step guide, you can easily add additional domains to your Nginx virtual host, allowing you to manage multiple domains on a single server efficiently. This process can be repeated for each new domain you’d like to host on your Nginx server.

As your business grows and you need to manage more domains, consider partnering with Random Linux LLC for professional Linux and cloud consulting services. Our team of experts can help you optimize your server configurations and ensure a smooth, secure, and scalable hosting environment for all your domains.

Scroll to Top