Short answer

Give each site a folder in /var/www and a config file in /etc/nginx/sites-available/ with its own server_name and root. Link the file into /etc/nginx/sites-enabled/, run sudo nginx -t, then sudo systemctl reload nginx. Test before DNS with curl -H 'Host: example.com' http://localhost.

Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04, every step is the same. Everything that differed

Before you start

  • An Ubuntu 26.04 or 24.04 server with Nginx installed and the firewall open for it (install Nginx), and a user with sudo.
  • The domain names you will use. This page uses example.com and example.net: put yours in their place. DNS does not have to point at the server yet; step 4 tests without it.
  • A server block is Nginx’s word for what Apache calls a virtual host: one block per site, chosen by the name the browser asks for.

Step 1: Make a folder and a page for each site

Server
$ sudo mkdir -p /var/www/example.com /var/www/example.net
Server
$ echo '<h1>example.com</h1>' | sudo tee /var/www/example.com/index.html<h1>example.com</h1>
Output hidden (1 line)
Server
$ echo '<h1>example.net</h1>' | sudo tee /var/www/example.net/index.html<h1>example.net</h1>
Output hidden (1 line)

The files belong to root and everyone may read them. That is all Nginx needs: it reads the files as the user www-data, and does not need to own them or write to them.

Server
$ ls -l /var/www/example.comtotal 4-rw-r--r-- 1 root root 21 Nov 18 22:52 index.html
Output hidden (2 lines)

Step 2: Write one config file per site

server_name lists every name the site answers to; root is its folder. The two log lines give the site its own logs, so one site’s traffic is not mixed with another’s. Write the file (or create it with sudo nano and paste the part between the EOF lines):

Server
$ sudo tee /etc/nginx/sites-available/example.com > /dev/null <<'EOF'server {    listen 80;    listen [::]:80;    server_name example.com www.example.com;    root /var/www/example.com;    index index.html;    access_log /var/log/nginx/example.com.access.log;    error_log /var/log/nginx/example.com.error.log;}EOF

The second site is the same file with its own names:

Server
$ sudo tee /etc/nginx/sites-available/example.net > /dev/null <<'EOF'server {    listen 80;    listen [::]:80;    server_name example.net www.example.net;    root /var/www/example.net;    index index.html;    access_log /var/log/nginx/example.net.access.log;    error_log /var/log/nginx/example.net.error.log;}EOF

Step 3: Turn the sites on

Nginx reads only what is in sites-enabled. A site is turned on with a link to its file, made with the full path:

Server
$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Server
$ sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/
Server
$ ls -l /etc/nginx/sites-enabled/total 0lrwxrwxrwx 1 root root 34 Nov 18 22:52 default -> /etc/nginx/sites-available/defaultlrwxrwxrwx 1 root root 38 Nov 18 22:52 example.com -> /etc/nginx/sites-available/example.comlrwxrwxrwx 1 root root 38 Nov 18 22:52 example.net -> /etc/nginx/sites-available/example.net
Output hidden (4 lines)

Test, then reload. A reload keeps the sites up while the new config loads:

Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx

Step 4: Test each site before DNS points at the server

Nginx picks the site from the name in the request’s Host header, so you can ask for any name without DNS:

Server
$ curl -H 'Host: example.com' http://localhost<h1>example.com</h1>
Output hidden (1 line)
Server
$ curl -H 'Host: example.net' http://localhost<h1>example.net</h1>
Output hidden (1 line)
Server
$ curl -H 'Host: www.example.net' http://localhost<h1>example.net</h1>
Output hidden (1 line)

From your own computer the same works with the server’s address: curl -H 'Host: example.com' http://203.0.113.10/ (your server’s address in place of 203.0.113.10). In the test run each name was requested from another machine this way and got its own page. Each request is written to that site’s own log:

Server
$ sudo tail -n 1 /var/log/nginx/example.net.access.log203.0.113.1 - - [18/Nov/2026:22:52:59 +0000] "GET / HTTP/1.1" 200 21 "-" "curl/8.5.0"
Output hidden (1 line)

Step 5: Decide what a name with no site gets

Anyone can point a domain at your server’s address, and bots ask for it by bare IP address. A name that no block lists does not get an error. It gets the port’s default server, which is still Ubuntu’s default site:

Server
$ curl -s -H 'Host: other.example.org' http://localhost | grep '<h1>'<h1>Welcome to nginx!</h1>
Output hidden (1 line)
Server
$ grep -n default_server /etc/nginx/sites-available/default22:	listen 80 default_server;23:	listen [::]:80 default_server;27:	# listen 443 ssl default_server;28:	# listen [::]:443 ssl default_server;
Output hidden (4 lines)

Most guides say to remove the default site. Do that and the unknown name gets one of YOUR sites: with no default_server left, Nginx uses the first block it read for the port, and the files are read in alphabetical order. After removing the link, test and reload as in step 3:

Server
$ sudo rm /etc/nginx/sites-enabled/default
Server
$ curl -H 'Host: other.example.org' http://localhost<h1>example.com</h1>
Output hidden (1 line)

In the test a request by bare IP address from outside got example.com as well. Search engines can then index your site under someone else’s domain. Add a catch-all block that answers unknown names with nothing, on HTTP and on HTTPS:

Server
$ sudo tee /etc/nginx/sites-available/catch-all > /dev/null <<'EOF'server {    listen 80 default_server;    listen [::]:80 default_server;    listen 443 ssl default_server;    listen [::]:443 ssl default_server;    server_name _;    ssl_reject_handshake on;    return 444;}EOF
  • default_server makes this block the one for any name no other block lists.
  • return 444 closes the connection without an answer.
  • ssl_reject_handshake on refuses HTTPS for unknown names before any certificate is sent, so this block needs no certificate. Without it, once a site has HTTPS, an unknown name on port 443 gets that site and its certificate.
Server
$ sudo ln -s /etc/nginx/sites-available/catch-all /etc/nginx/sites-enabled/
Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx

An unknown name now gets nothing, over HTTP and HTTPS, and your sites still answer:

Server
$ curl -H 'Host: other.example.org' http://localhostcurl: (52) Empty reply from server
Output hidden (1 line)
Server
$ curl -k https://localhostcurl: (35) TLS connect error: error:0A000458:SSL routines::tlsv1 unrecognized name
Output hidden (1 line)
Server
$ curl -H 'Host: example.com' http://localhost<h1>example.com</h1>
Output hidden (1 line)

When the site gets its certificate (Let’s Encrypt for Nginx), certbot adds port 443 to the site’s own block, and the catch-all keeps covering every other name.

Turn a site off

Remove its link and reload. The config file stays in sites-available, so turning it on again is the ln -s from step 3:

Server
$ sudo rm /etc/nginx/sites-enabled/example.net
Server
$ curl -H 'Host: example.net' http://localhostcurl: (52) Empty reply from server
Output hidden (1 line)
Server
$ ls /etc/nginx/sites-available/catch-all  default  example.com  example.net
Output hidden (1 line)

The output above was taken after the reload (sudo nginx -t, then sudo systemctl reload nginx): the name now falls to the catch-all.

Mistakes and the errors they print

“a duplicate default server for 0.0.0.0:80”

Two blocks say default_server for the same port. In the test the default site was linked again beside the catch-all. The error names the second file and line; remove one of the two:

Server
$ sudo nginx -t2026/11/18 22:53:12 [emerg] 6933#6933: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default:22nginx: configuration file /etc/nginx/nginx.conf test failed
Output hidden (2 lines)

“conflicting server name … ignored”

Two blocks list the same name, usually a copied file whose server_name was not changed. In the test example.net’s file still said example.com. This is only a warning: the test passes, the reload works, and the second file is ignored for that name, so the site you just made never appears:

Server
$ sudo nginx -t2026/11/18 22:53:13 [warn] 7174#7174: conflicting server name "example.com" on 0.0.0.0:80, ignored2026/11/18 22:53:13 [warn] 7174#7174: conflicting server name "www.example.com" on 0.0.0.0:80, ignored2026/11/18 22:53:13 [warn] 7174#7174: conflicting server name "example.com" on [::]:80, ignored2026/11/18 22:53:13 [warn] 7174#7174: conflicting server name "www.example.com" on [::]:80, ignorednginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (6 lines)

Fix the server_name line in the file you copied, then test and reload.

“open() … sites-enabled/… failed (2: No such file or directory)”

The link was made with a relative path. ln does not check the target and prints nothing:

Server
$ cd /etc/nginx && sudo ln -s sites-available/example.net sites-enabled/
Server
$ sudo nginx -t2026/11/18 22:53:15 [emerg] 7747#7747: open() "/etc/nginx/sites-enabled/example.net" failed (2: No such file or directory) in /etc/nginx/nginx.conf:61nginx: configuration file /etc/nginx/nginx.conf test failed
Output hidden (2 lines)

A relative link is read from the folder the link is in, so it points to sites-enabled/sites-available/example.net, which does not exist:

Server
$ ls -l /etc/nginx/sites-enabled/example.netlrwxrwxrwx 1 root root 27 Nov 18 22:53 /etc/nginx/sites-enabled/example.net -> sites-available/example.net
Output hidden (1 line)

Remove it with sudo rm /etc/nginx/sites-enabled/example.net and make it again with the full path, as in step 3.

403 Forbidden: “directory index of … is forbidden”

The folder has no index.html (in the test the page had been renamed to home.html). Nginx will not list a folder, so it answers 403:

Server
$ curl -I -H 'Host: example.net' http://localhostHTTP/1.1 403 ForbiddenServer: nginx/1.28.3 (Ubuntu)Date: Wed, 18 Nov 2026 22:53:17 GMTContent-Type: text/htmlContent-Length: 162Connection: keep-alive
Output hidden (6 lines)
Server
$ sudo tail -n 1 /var/log/nginx/example.net.error.log2026/11/18 22:53:17 [error] 7997#7997: *18 directory index of "/var/www/example.net/" is forbidden, client: ::1, server: example.net, request: "HEAD / HTTP/1.1", host: "example.net"
Output hidden (1 line)

Name the page index.html, or put its name on the index line of the block.

403 Forbidden for a site in your home folder

In the test the site’s root was pointed at a folder in the sudo user’s home:

Server
$ mkdir ~/site && echo '<h1>from home</h1>' > ~/site/index.html
Server
$ curl -I -H 'Host: example.net' http://localhostHTTP/1.1 403 ForbiddenServer: nginx/1.28.3 (Ubuntu)Date: Wed, 18 Nov 2026 22:53:20 GMTContent-Type: text/htmlContent-Length: 162Connection: keep-alive
Output hidden (6 lines)
Server
$ sudo tail -n 1 /var/log/nginx/example.net.error.log2026/11/18 22:53:20 [error] 8563#8563: *19 "/home/deploy/site/index.html" is forbidden (13: Permission denied), client: ::1, server: example.net, request: "HEAD / HTTP/1.1", host: "example.net"
Output hidden (1 line)

On Ubuntu 26.04 and 24.04 a home folder is drwxr-x---: only its owner and group may enter it, and Nginx’s user www-data is neither:

Server
$ ls -ld /home/deploydrwxr-x--- 5 deploy deploy 4096 Nov 18 22:53 /home/deploy
Output hidden (1 line)

Keep sites in /var/www. Opening your home folder to every user on the server to fix this trades one problem for a worse one.

What these steps changed on the server

Both runs recorded the server before the first step and after the last (see the Tested on box below). Six files were added in /etc/nginx: the three server blocks in sites-available and their three links in sites-enabled; the link to the default site was removed. Nginx now also listens on port 443, for the HTTPS catch-all, although no site has a certificate yet. No package or service changed.

Ubuntu 26.04 vs 24.04: what changed

Ubuntu 26.04 ships Nginx 1.28 and 24.04 ships Nginx 1.24, but for server blocks the steps, the warning and the Nginx error messages were the same on both runs. Only two details printed differently:

WhatUbuntu 26.04Ubuntu 24.04
SystemUbuntu 26.04.1 LTS7.0.0-43-genericUbuntu 24.04.5 LTS6.8.0-147-generic
nginx1.28.3-2ubuntu1.121.24.0-2ubuntu7.19
nginx-common1.28.3-2ubuntu1.121.24.0-2ubuntu7.19
curl8.18.0-1ubuntu2.88.5.0-2ubuntu10.16
curl’s error when the HTTPS catch-all refuses the handshakecurl: (35) TLS connect error: error:0A000458:SSL routines::tlsv1 unrecognized namecurl: (35) OpenSSL/3.0.13: error:0A000458:SSL routines::tlsv1 unrecognized name
The line of nginx.conf named in the broken-link error (the include /etc/nginx/sites-enabled/*; line)nginx.conf:61nginx.conf:60
ProofRun log, 43 checks passedRun log, 43 checks passed

Remove a site completely

Server
$ sudo rm /etc/nginx/sites-enabled/example.net /etc/nginx/sites-available/example.net
Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx
Server
$ sudo rm -r /var/www/example.net

Its logs stay until you delete them too:

Server
$ ls /var/log/nginx/access.log  error.log  example.com.access.log  example.com.error.log  example.net.access.log  example.net.error.log
Output hidden (1 line)