ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/nginx-server-blocks-ubuntu-24-04 Check scripts/live/checks/nginx-server-blocks-ubuntu-24-04.mjs (sha256 4937a204d0c90240af23391732fe445d1de7e8dadfd0bef89fa6648b038c8a02) Ran at 2026-11-12T07:46:17Z (82 s) Result PASS, all 41 claims held Tested on System Ubuntu 24.04.5 LTS Kernel 6.8.0-147-generic Package nginx 1.24.0-2ubuntu7.19 Package nginx-common 1.24.0-2ubuntu7.19 Package curl 8.5.0-2ubuntu10.16 Setup A fresh Ubuntu 24.04 server from Ubuntu’s cloud image with ufw on and Nginx installed, reached over SSH as a sudo user; each site requested from a second machine by name. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ Claims (41), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) nginx installed and running, ufw on with SSH and Nginx Full allowed, as after the Install Nginx article | Status: active | | To Action From | -- ------ ---- | OpenSSH ALLOW Anywhere | Nginx Full ALLOW Anywhere | OpenSSH (v6) ALLOW Anywhere (v6) | Nginx Full (v6) ALLOW Anywhere (v6) 3. ok (probe) before any server block, every name gets the default page from outside | 200 4. ok tee prints each page it wrote |

example.com

|

example.net

5. ok the page belongs to root and is readable by everyone (-rw-r--r-- root root): no chown to www-data needed | total 4 | -rw-r--r-- 1 root root 21 Nov 12 07:47 index.html 6. ok both server blocks are written (tee prints nothing with > /dev/null) | | 7. ok sites-enabled holds three links: default, example.com, example.net, each pointing into sites-available | total 0 | lrwxrwxrwx 1 root root 34 Nov 12 07:47 default -> /etc/nginx/sites-available/default | lrwxrwxrwx 1 root root 38 Nov 12 07:47 example.com -> /etc/nginx/sites-available/example.com | lrwxrwxrwx 1 root root 38 Nov 12 07:47 example.net -> /etc/nginx/sites-available/example.net 8. ok nginx -t is successful | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 9. ok reload prints nothing 10. ok each name gets its own site: example.com, example.net, and www.example.net the same as example.net |

example.com

|

example.net

|

example.net

11. ok (probe) from outside, through the firewall, each name gets its own page | 200

example.com

| 200

example.net

12. ok the request for example.net is in example.net.access.log | 203.0.113.1 - - [12/Nov/2026:07:47:22 +0000] "GET / HTTP/1.1" 200 21 "-" "curl/8.5.0" 13. ok (probe) the main access.log did not get the site requests | 1 14. ok a name no block lists gets the default site ("Welcome to nginx!"): its listen line says default_server |

Welcome to nginx!

15. ok the default site is the one with "listen 80 default_server;" | 22: listen 80 default_server; | 23: listen [::]:80 default_server; | 27: # listen 443 ssl default_server; | 28: # listen [::]:443 ssl default_server; 16. ok with the default site off and no default_server anywhere, an unknown name gets example.com: the FIRST block in sites-enabled (alphabetical) |

example.com

17. ok (probe) from outside, a request by IP address also gets example.com | 200

example.com

18. ok the catch-all block is written 19. ok nginx -t is successful: "listen 443 ssl" needs no certificate with ssl_reject_handshake on | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 20. ok an unknown name now gets no page at all: "curl: (52) Empty reply from server" | curl: (52) Empty reply from server 21. ok over HTTPS the handshake is refused (no certificate is handed out): curl (35) … unrecognized name | curl: (35) OpenSSL/3.0.13: error:0A000458:SSL routines::tlsv1 unrecognized name 22. ok example.com still answers |

example.com

23. ok (probe) from outside: by IP address no answer, by name the site | 000 | 200

example.net

24. ok with its link removed and a reload, example.net falls to the catch-all (52 Empty reply) | curl: (52) Empty reply from server 25. ok its config file is still in sites-available | catch-all default example.com example.net 26. ok (turned on again, example.net answers) 27. ok (tested on) the box reports its OS, kernel and the version of 3 package(s) | PRETTY_NAME="Ubuntu 24.04.5 LTS" | VIRT=none | KERNEL=6.8.0-147-generic | PKG curl 8.5.0-2ubuntu10.16 | PKG nginx 1.24.0-2ubuntu7.19 | PKG nginx-common 1.24.0-2ubuntu7.19 28. ok two default_server blocks on port 80: "[emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/…", test failed | 2026/11/12 07:47:29 [emerg] 5000#5000: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default:22 | nginx: configuration file /etc/nginx/nginx.conf test failed 29. ok the same server_name in two files: only a [warn] "conflicting server name "example.com" on 0.0.0.0:80, ignored", and the test is SUCCESSFUL | 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "example.com" on 0.0.0.0:80, ignored | 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "www.example.com" on 0.0.0.0:80, ignored | 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "example.com" on [::]:80, ignored | 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "www.example.com" on [::]:80, ignored | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 30. ok (the first file read wins: example.com still serves its own page) |

example.com

31. ok ln with a relative path prints nothing (it does not check the target) 32. ok nginx -t: [emerg] open() "/etc/nginx/sites-enabled/example.net" failed (2: No such file or directory) in /etc/nginx/nginx.conf:NN | 2026/11/12 07:47:33 [emerg] 5653#5653: open() "/etc/nginx/sites-enabled/example.net" failed (2: No such file or directory) in /etc/nginx/nginx.conf:60 | nginx: configuration file /etc/nginx/nginx.conf test failed 33. ok the link points to sites-available/example.net INSIDE sites-enabled, which does not exist | lrwxrwxrwx 1 root root 27 Nov 12 07:47 /etc/nginx/sites-enabled/example.net -> sites-available/example.net 34. ok a folder with no index.html: "HTTP/1.1 403 Forbidden" | HTTP/1.1 403 Forbidden | Server: nginx/1.24.0 (Ubuntu) | Date: Thu, 12 Nov 2026 07:47:34 GMT | Content-Type: text/html | Content-Length: 162 | Connection: keep-alive 35. ok the site's error log: directory index of "/var/www/example.net/" is forbidden | 2026/11/12 07:47:34 [error] 5851#5851: *18 directory index of "/var/www/example.net/" is forbidden, client: ::1, server: example.net, request: "HEAD / HTTP/1.1", host: "example.net" 36. ok root in /home/deploy/site: "HTTP/1.1 403 Forbidden" | HTTP/1.1 403 Forbidden | Server: nginx/1.24.0 (Ubuntu) | Date: Thu, 12 Nov 2026 07:47:36 GMT | Content-Type: text/html | Content-Length: 162 | Connection: keep-alive 37. ok the error log: "/home/deploy/site/index.html" is forbidden (13: Permission denied) | 2026/11/12 07:47:36 [error] 6299#6299: *19 "/home/deploy/site/index.html" is forbidden (13: Permission denied), client: ::1, server: example.net, request: "HEAD / HTTP/1.1", host: "example.net" 38. ok the home folder is drwxr-x--- (750): www-data may not enter it | drwxr-x--- 5 deploy deploy 4096 Nov 12 07:47 /home/deploy 39. ok (back in /var/www, example.net answers again) 40. ok with both files gone the test is successful | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok | nginx: configuration file /etc/nginx/nginx.conf test is successful 41. ok its log files stay in /var/log/nginx until you delete them | access.log error.log example.com.access.log example.com.error.log example.net.access.log example.net.error.log ------------------------------------------------------------------------------ Commands and what they printed (46) ------------------------------------------------------------------------------ $ sudo mkdir -p /var/www/example.com /var/www/example.net $ echo '

example.com

' | sudo tee /var/www/example.com/index.html

example.com

$ echo '

example.net

' | sudo tee /var/www/example.net/index.html

example.net

$ ls -l /var/www/example.com total 4 -rw-r--r-- 1 root root 21 Nov 12 07:47 index.html $ 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 $ 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 $ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ $ sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/ $ ls -l /etc/nginx/sites-enabled/ total 0 lrwxrwxrwx 1 root root 34 Nov 12 07:47 default -> /etc/nginx/sites-available/default lrwxrwxrwx 1 root root 38 Nov 12 07:47 example.com -> /etc/nginx/sites-available/example.com lrwxrwxrwx 1 root root 38 Nov 12 07:47 example.net -> /etc/nginx/sites-available/example.net $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx $ curl -H 'Host: example.com' http://localhost

example.com

$ curl -H 'Host: example.net' http://localhost

example.net

$ curl -H 'Host: www.example.net' http://localhost

example.net

$ sudo tail -n 1 /var/log/nginx/example.net.access.log 203.0.113.1 - - [12/Nov/2026:07:47:22 +0000] "GET / HTTP/1.1" 200 21 "-" "curl/8.5.0" $ curl -s -H 'Host: other.example.org' http://localhost | grep '

'

Welcome to nginx!

$ grep -n default_server /etc/nginx/sites-available/default 22: listen 80 default_server; 23: listen [::]:80 default_server; 27: # listen 443 ssl default_server; 28: # listen [::]:443 ssl default_server; $ sudo rm /etc/nginx/sites-enabled/default $ curl -H 'Host: other.example.org' http://localhost

example.com

$ 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 $ sudo ln -s /etc/nginx/sites-available/catch-all /etc/nginx/sites-enabled/ $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx $ curl -H 'Host: other.example.org' http://localhost curl: (52) Empty reply from server $ curl -k https://localhost curl: (35) OpenSSL/3.0.13: error:0A000458:SSL routines::tlsv1 unrecognized name $ curl -H 'Host: example.com' http://localhost

example.com

$ sudo rm /etc/nginx/sites-enabled/example.net $ curl -H 'Host: example.net' http://localhost curl: (52) Empty reply from server $ ls /etc/nginx/sites-available/ catch-all default example.com example.net $ sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/ $ sudo nginx -t 2026/11/12 07:47:29 [emerg] 5000#5000: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/default:22 nginx: configuration file /etc/nginx/nginx.conf test failed $ sudo nginx -t 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "example.com" on 0.0.0.0:80, ignored 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "www.example.com" on 0.0.0.0:80, ignored 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "example.com" on [::]:80, ignored 2026/11/12 07:47:30 [warn] 5190#5190: conflicting server name "www.example.com" on [::]:80, ignored nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ cd /etc/nginx && sudo ln -s sites-available/example.net sites-enabled/ $ sudo nginx -t 2026/11/12 07:47:33 [emerg] 5653#5653: open() "/etc/nginx/sites-enabled/example.net" failed (2: No such file or directory) in /etc/nginx/nginx.conf:60 nginx: configuration file /etc/nginx/nginx.conf test failed $ ls -l /etc/nginx/sites-enabled/example.net lrwxrwxrwx 1 root root 27 Nov 12 07:47 /etc/nginx/sites-enabled/example.net -> sites-available/example.net $ curl -I -H 'Host: example.net' http://localhost HTTP/1.1 403 Forbidden Server: nginx/1.24.0 (Ubuntu) Date: Thu, 12 Nov 2026 07:47:34 GMT Content-Type: text/html Content-Length: 162 Connection: keep-alive $ sudo tail -n 1 /var/log/nginx/example.net.error.log 2026/11/12 07:47:34 [error] 5851#5851: *18 directory index of "/var/www/example.net/" is forbidden, client: ::1, server: example.net, request: "HEAD / HTTP/1.1", host: "example.net" $ mkdir ~/site && echo '

from home

' > ~/site/index.html $ curl -I -H 'Host: example.net' http://localhost HTTP/1.1 403 Forbidden Server: nginx/1.24.0 (Ubuntu) Date: Thu, 12 Nov 2026 07:47:36 GMT Content-Type: text/html Content-Length: 162 Connection: keep-alive $ sudo tail -n 1 /var/log/nginx/example.net.error.log 2026/11/12 07:47:36 [error] 6299#6299: *19 "/home/deploy/site/index.html" is forbidden (13: Permission denied), client: ::1, server: example.net, request: "HEAD / HTTP/1.1", host: "example.net" $ ls -ld /home/deploy drwxr-x--- 5 deploy deploy 4096 Nov 12 07:47 /home/deploy $ sudo rm /etc/nginx/sites-enabled/example.net /etc/nginx/sites-available/example.net $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful $ sudo systemctl reload nginx $ sudo rm -r /var/www/example.net $ ls /var/log/nginx/ access.log error.log example.com.access.log example.com.error.log example.net.access.log example.net.error.log ------------------------------------------------------------------------------ The check's source (scripts/live/checks/nginx-server-blocks-ubuntu-24-04.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB: Nginx server blocks on Ubuntu 24.04: two sites on one server (example.com, example.net), each with its own * folder, config file and logs; turn them on, test before DNS (Host header); what a name that matches no block gets * (the default site, then, with it removed, the FIRST block in sites-enabled); a catch-all for HTTP and HTTPS * (return 444, ssl_reject_handshake); turn a site off; the mistakes and the errors they print: a duplicate default * server, a conflicting server name, a broken symlink, 403 for a folder with no index, 403 for a site in a home folder. * * The server is a fresh VM box from Ubuntu's cloud image, reached as the sudo user `deploy`, as the Install Nginx * article leaves it (hidden setup: ufw on with OpenSSH and 'Nginx Full' allowed, nginx installed). "From outside" is * real: the VM's port 80 is forwarded to 127.0.0.1:PROBE_PORT on the laptop, and the probe sends the Host header a * browser would send for that name. */ import { spawnSync } from 'node:child_process' import { PROBE_PORT } from '../box/vm.mjs' import { bareBox, reportBox } from '../lib.mjs' export const meta = {} /** What a browser on another machine gets for http:///: [status, body] ('000' = no answer / empty reply). */ const outside = (name) => { const r = spawnSync('curl', ['-s', '-m', '6', '-H', `Host: ${name}`, '-w', '\n%{http_code}', `http://127.0.0.1:${PROBE_PORT}/`], { encoding: 'utf8' }) const lines = r.stdout.split('\n') return [lines.pop(), lines.join('\n').trim()] } const block = (name) => `server { listen 80; listen [::]:80; server_name ${name} www.${name}; root /var/www/${name}; index index.html; access_log /var/log/nginx/${name}.access.log; error_log /var/log/nginx/${name}.error.log; }` const CATCH_ALL = `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; }` const tee = (path, body) => `sudo tee ${path} > /dev/null <<'EOF'\n${body}\nEOF` const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, L } = sudoUser() L('sudo true') // as the Install Nginx article leaves the server L('sudo ufw allow OpenSSH && sudo ufw --force enable') L('sudo apt-get update -q && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -q nginx', 900000) L("sudo ufw allow 'Nginx Full'") ctx.check('(setup) nginx installed and running, ufw on with SSH and Nginx Full allowed, as after the Install Nginx article', L('systemctl is-active nginx') === 'active' && /Nginx Full/.test(L('sudo ufw status')), L('sudo ufw status')) const [s0] = outside('example.com') ctx.check('(probe) before any server block, every name gets the default page from outside', s0 === '200', s0) // ── step 1: a folder and a page per site ───────────────────────────────────────────────── run('sudo mkdir -p /var/www/example.com /var/www/example.net', { id: 'mkdir' }) const p1 = run("echo '

example.com

' | sudo tee /var/www/example.com/index.html", { id: 'page-com' }) const p2 = run("echo '

example.net

' | sudo tee /var/www/example.net/index.html", { id: 'page-net' }) ctx.check('tee prints each page it wrote', p1.out === '

example.com

' && p2.out === '

example.net

', `${p1.out} | ${p2.out}`) const lsl = run('ls -l /var/www/example.com', { id: 'ls-page' }) ctx.check('the page belongs to root and is readable by everyone (-rw-r--r-- root root): no chown to www-data needed', /^-rw-r--r-- 1 root root \d+ .* index\.html$/m.test(lsl.out), lsl.out) // ── step 2: one config file per site ───────────────────────────────────────────────────── const w1 = run(tee('/etc/nginx/sites-available/example.com', block('example.com')), { id: 'block-com' }) const w2 = run(tee('/etc/nginx/sites-available/example.net', block('example.net')), { id: 'block-net' }) ctx.check('both server blocks are written (tee prints nothing with > /dev/null)', w1.exit === 0 && w1.out === '' && w2.exit === 0 && w2.out === '', `${w1.out}|${w2.out}`) // ── step 3: turn them on ───────────────────────────────────────────────────────────────── run('sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/', { id: 'enable-com' }) run('sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/', { id: 'enable-net' }) const en = run('ls -l /etc/nginx/sites-enabled/', { id: 'ls-enabled' }) ctx.check('sites-enabled holds three links: default, example.com, example.net, each pointing into sites-available', /default -> \/etc\/nginx\/sites-available\/default/.test(en.out) && /example\.com -> \/etc\/nginx\/sites-available\/example\.com/.test(en.out) && /example\.net -> \/etc\/nginx\/sites-available\/example\.net/.test(en.out), en.out) const t1 = run('sudo nginx -t', { id: 'test-1' }) ctx.check('nginx -t is successful', t1.exit === 0 && /test is successful/.test(t1.out), t1.out) const r1 = run('sudo systemctl reload nginx', { id: 'reload-1' }) ctx.check('reload prints nothing', r1.exit === 0 && r1.out === '', r1.out) // ── step 4: test before DNS ────────────────────────────────────────────────────────────── const c1 = run("curl -H 'Host: example.com' http://localhost", { id: 'curl-com' }) const c2 = run("curl -H 'Host: example.net' http://localhost", { id: 'curl-net' }) const c3 = run("curl -H 'Host: www.example.net' http://localhost", { id: 'curl-www' }) ctx.check('each name gets its own site: example.com, example.net, and www.example.net the same as example.net', c1.out === '

example.com

' && c2.out === '

example.net

' && c3.out === '

example.net

', `${c1.out} | ${c2.out} | ${c3.out}`) const [o1, b1] = outside('example.com') const [o2, b2] = outside('example.net') ctx.check('(probe) from outside, through the firewall, each name gets its own page', o1 === '200' && b1 === '

example.com

' && o2 === '200' && b2 === '

example.net

', `${o1} ${b1} | ${o2} ${b2}`) // per-site logs const lg = run('sudo tail -n 1 /var/log/nginx/example.net.access.log', { id: 'log-net' }) ctx.check('the request for example.net is in example.net.access.log', /"GET \/ HTTP\/1\.1" 200 /.test(lg.out), lg.out) const lgc = L('sudo grep -c . /var/log/nginx/access.log || true') ctx.check('(probe) the main access.log did not get the site requests', /^\d+$/.test(lgc) && Number(lgc) <= 1, lgc) // ── a name that matches no block ───────────────────────────────────────────────────────── const u1 = run("curl -s -H 'Host: other.example.org' http://localhost | grep '

'", { id: 'unknown-default' }) ctx.check('a name no block lists gets the default site ("Welcome to nginx!"): its listen line says default_server', u1.out === '

Welcome to nginx!

', u1.out) const dg = run("grep -n default_server /etc/nginx/sites-available/default", { id: 'grep-default' }) ctx.check('the default site is the one with "listen 80 default_server;"', /listen 80 default_server;/.test(dg.out), dg.out) run('sudo rm /etc/nginx/sites-enabled/default', { id: 'rm-default' }) L('sudo nginx -t && sudo systemctl reload nginx') const u2 = run("curl -H 'Host: other.example.org' http://localhost", { id: 'unknown-first' }) ctx.check('with the default site off and no default_server anywhere, an unknown name gets example.com: the FIRST block in sites-enabled (alphabetical)', u2.out === '

example.com

', u2.out) const [o3, b3] = outside('203.0.113.10') ctx.check('(probe) from outside, a request by IP address also gets example.com', o3 === '200' && b3 === '

example.com

', `${o3} ${b3}`) // ── the catch-all ──────────────────────────────────────────────────────────────────────── const wc = run(tee('/etc/nginx/sites-available/catch-all', CATCH_ALL), { id: 'block-catch' }) ctx.check('the catch-all block is written', wc.exit === 0 && wc.out === '', wc.out) run('sudo ln -s /etc/nginx/sites-available/catch-all /etc/nginx/sites-enabled/', { id: 'enable-catch' }) const t2 = run('sudo nginx -t', { id: 'test-catch' }) ctx.check('nginx -t is successful: "listen 443 ssl" needs no certificate with ssl_reject_handshake on', t2.exit === 0 && /test is successful/.test(t2.out), t2.out) run('sudo systemctl reload nginx', { id: 'reload-catch' }) const u3 = run("curl -H 'Host: other.example.org' http://localhost", { id: 'unknown-444' }) ctx.check('an unknown name now gets no page at all: "curl: (52) Empty reply from server"', /curl: \(52\) Empty reply from server/.test(u3.out), u3.out) const u4 = run('curl -k https://localhost', { id: 'unknown-tls' }) ctx.check('over HTTPS the handshake is refused (no certificate is handed out): curl (35) … unrecognized name', /curl: \(35\)/.test(u4.out) && /unrecognized name/i.test(u4.out), u4.out) const c4 = run("curl -H 'Host: example.com' http://localhost", { id: 'curl-com-2' }) ctx.check('example.com still answers', c4.out === '

example.com

', c4.out) const [o4] = outside('203.0.113.10') const [o5, b5] = outside('example.net') ctx.check('(probe) from outside: by IP address no answer, by name the site', o4 === '000' && o5 === '200' && b5 === '

example.net

', `${o4} | ${o5} ${b5}`) // ── turn a site off ────────────────────────────────────────────────────────────────────── run('sudo rm /etc/nginx/sites-enabled/example.net', { id: 'disable-net' }) L('sudo nginx -t && sudo systemctl reload nginx') const d1 = run("curl -H 'Host: example.net' http://localhost", { id: 'curl-net-off' }) ctx.check('with its link removed and a reload, example.net falls to the catch-all (52 Empty reply)', /curl: \(52\) Empty reply from server/.test(d1.out), d1.out) const d2 = run('ls /etc/nginx/sites-available/', { id: 'ls-available' }) ctx.check('its config file is still in sites-available', /example\.net/.test(d2.out), d2.out) run('sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/', { id: 'enable-net-again' }) L('sudo nginx -t && sudo systemctl reload nginx') ctx.check('(turned on again, example.net answers)', L("curl -s -H 'Host: example.net' http://localhost") === '

example.net

', '') reportBox( ctx, L, 'A fresh Ubuntu 24.04 server from Ubuntu’s cloud image with ufw on and Nginx installed, reached over SSH as a sudo user; each site requested from a second machine by name.', ['nginx', 'nginx-common', 'curl'], ) // ── mistakes ───────────────────────────────────────────────────────────────────────────── // 1. the default site turned back on beside the catch-all L('sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/') const m1 = run('sudo nginx -t', { id: 'err-duplicate' }) ctx.check('two default_server blocks on port 80: "[emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/…", test failed', m1.exit !== 0 && /\[emerg\] \d+#\d+: a duplicate default server for 0\.0\.0\.0:80 in \/etc\/nginx\/sites-enabled\/\S+:\d+/.test(m1.out) && /test failed/.test(m1.out), m1.out) L('sudo rm /etc/nginx/sites-enabled/default') // 2. example.net made by copying example.com and forgetting server_name L("sudo sed -i 's/server_name example.net www.example.net;/server_name example.com www.example.com;/' /etc/nginx/sites-available/example.net") const m2 = run('sudo nginx -t', { id: 'err-conflict' }) ctx.check('the same server_name in two files: only a [warn] "conflicting server name "example.com" on 0.0.0.0:80, ignored", and the test is SUCCESSFUL', m2.exit === 0 && /\[warn\] \d+#\d+: conflicting server name "example\.com" on 0\.0\.0\.0:80, ignored/.test(m2.out) && /test is successful/.test(m2.out), m2.out) L('sudo systemctl reload nginx') const m2c = L("curl -s -H 'Host: example.com' http://localhost") ctx.check('(the first file read wins: example.com still serves its own page)', m2c === '

example.com

', m2c) L("sudo sed -i '0,/server_name example.com www.example.com;/s//server_name example.net www.example.net;/' /etc/nginx/sites-available/example.net") L('sudo nginx -t && sudo systemctl reload nginx') // 3. the link made with a relative path L('sudo rm /etc/nginx/sites-enabled/example.net') const m3l = run('cd /etc/nginx && sudo ln -s sites-available/example.net sites-enabled/', { id: 'err-link-make' }) ctx.check('ln with a relative path prints nothing (it does not check the target)', m3l.exit === 0 && m3l.out === '', m3l.out) const m3 = run('sudo nginx -t', { id: 'err-link' }) ctx.check('nginx -t: [emerg] open() "/etc/nginx/sites-enabled/example.net" failed (2: No such file or directory) in /etc/nginx/nginx.conf:NN', m3.exit !== 0 && /\[emerg\] \d+#\d+: open\(\) "\/etc\/nginx\/sites-enabled\/example\.net" failed \(2: No such file or directory\) in \/etc\/nginx\/nginx\.conf:\d+/.test(m3.out), m3.out) const m3s = run('ls -l /etc/nginx/sites-enabled/example.net', { id: 'err-link-ls' }) ctx.check('the link points to sites-available/example.net INSIDE sites-enabled, which does not exist', /example\.net -> sites-available\/example\.net$/.test(m3s.out), m3s.out) L('sudo rm /etc/nginx/sites-enabled/example.net && sudo ln -s /etc/nginx/sites-available/example.net /etc/nginx/sites-enabled/') L('sudo nginx -t && sudo systemctl reload nginx') // 4. no index.html in the folder L('sudo mv /var/www/example.net/index.html /var/www/example.net/home.html') const m4 = run("curl -I -H 'Host: example.net' http://localhost", { id: 'err-noindex' }) ctx.check('a folder with no index.html: "HTTP/1.1 403 Forbidden"', /^HTTP\/1\.1 403 Forbidden/.test(m4.out), m4.out) const m4l = run('sudo tail -n 1 /var/log/nginx/example.net.error.log', { id: 'err-noindex-log' }) ctx.check('the site\'s error log: directory index of "/var/www/example.net/" is forbidden', /directory index of "\/var\/www\/example\.net\/" is forbidden/.test(m4l.out), m4l.out) L('sudo mv /var/www/example.net/home.html /var/www/example.net/index.html') // 5. the site in the sudo user's home folder run('mkdir ~/site && echo \'

from home

\' > ~/site/index.html', { id: 'home-make' }) L("sudo sed -i 's#root /var/www/example.net;#root /home/deploy/site;#' /etc/nginx/sites-available/example.net") L('sudo nginx -t && sudo systemctl reload nginx') const m5 = run("curl -I -H 'Host: example.net' http://localhost", { id: 'err-home' }) ctx.check('root in /home/deploy/site: "HTTP/1.1 403 Forbidden"', /^HTTP\/1\.1 403 Forbidden/.test(m5.out), m5.out) const m5l = run('sudo tail -n 1 /var/log/nginx/example.net.error.log', { id: 'err-home-log' }) ctx.check('the error log: "/home/deploy/site/index.html" is forbidden (13: Permission denied)', /"\/home\/deploy\/site\/index\.html" is forbidden \(13: Permission denied\)/.test(m5l.out), m5l.out) const m5d = run('ls -ld /home/deploy', { id: 'err-home-ls' }) ctx.check('the home folder is drwxr-x--- (750): www-data may not enter it', /^drwxr-x--- \d+ deploy deploy /.test(m5d.out), m5d.out) L("sudo sed -i 's#root /home/deploy/site;#root /var/www/example.net;#' /etc/nginx/sites-available/example.net") L('sudo nginx -t && sudo systemctl reload nginx') ctx.check('(back in /var/www, example.net answers again)', L("curl -s -H 'Host: example.net' http://localhost") === '

example.net

', '') // ── undo: remove a site completely ─────────────────────────────────────────────────────── run('sudo rm /etc/nginx/sites-enabled/example.net /etc/nginx/sites-available/example.net', { id: 'undo-rm' }) const ut = run('sudo nginx -t', { id: 'undo-test' }) ctx.check('with both files gone the test is successful', ut.exit === 0 && /test is successful/.test(ut.out), ut.out) run('sudo systemctl reload nginx', { id: 'undo-reload' }) run('sudo rm -r /var/www/example.net', { id: 'undo-www' }) const ul = run('ls /var/log/nginx/', { id: 'undo-logs' }) ctx.check('its log files stay in /var/log/nginx until you delete them', /example\.net\.access\.log/.test(ul.out), ul.out) }) export default check