Nginx server blocks — equivalent to Apache virtual hosts — let you host multiple websites on a single server, each with its own domain name, document root, and configuration. This guide creates and enables a server block on Ubuntu 26.04 LTS.

Tested and valid on:

  • Ubuntu 26.04 LTS

Prerequisites

  • Ubuntu 26.04 LTS server with Nginx installed
  • A domain name pointing to your server’s IP
  • A user with sudo privileges

Step 1 – Create the Document Root

Replace example.com with your domain:

sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com

Step 2 – Create a Sample Index Page

nano /var/www/example.com/html/index.html

Add basic content:

Welcome to example.com

example.com is working!

Step 3 – Create the Server Block Config

sudo nano /etc/nginx/sites-available/example.com

Add this configuration:

server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html;
    index index.html index.htm index.php;

    server_name example.com www.example.com;

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

Step 4 – Enable the Server Block

Create a symlink in sites-enabled:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Step 5 – Avoid Hash Bucket Size Errors

Edit nginx.conf to uncomment:

sudo nano /etc/nginx/nginx.conf

Uncomment:

server_names_hash_bucket_size 64;

Step 6 – Test and Reload Nginx

sudo nginx -t
sudo systemctl reload nginx

Step 7 – Verify the Site

Test with curl using the Host header:

curl -H 'Host: example.com' http://your_server_ip

Conclusion

You can now host multiple sites on a single Ubuntu 26.04 LTS Nginx server. Repeat this process for each domain, then secure each one with a free Let’s Encrypt SSL certificate.