Short answer

Run sudo apt update, then sudo apt install -y nginx. If ufw is on, open the web ports with sudo ufw allow 'Nginx Full', then open http://<server address>/ in a browser: you see “Welcome to nginx!”. After every config change run sudo nginx -t, then sudo systemctl reload nginx.

Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04? 2 sections differ, each step marked “On Ubuntu 24.04” right under it: Step 3: Open the firewall and load the page, Step 5: Change the config without taking the site down. Everything that differed

Before you start

  • An Ubuntu 26.04 or 24.04 server and a user with sudo (create one).
  • The firewall on with SSH allowed (set up ufw). If ufw is off, skip the firewall part of step 3.
  • This installs the Nginx that Ubuntu ships: version 1.28 on 26.04, 1.24 on 24.04. Ubuntu keeps it patched for security, and automatic updates install those patches.

Step 1: Install Nginx

Server
$ sudo apt update[… 46 lines not shown …]Get:47 http://archive.ubuntu.com/ubuntu resolute-backports/multiverse amd64 Components [216 B]Get:48 http://archive.ubuntu.com/ubuntu resolute-backports/multiverse amd64 c-n-f Metadata [120 B]Fetched 32.7 MB in 16s (2065 kB/s)23 packages can be upgraded. Run 'apt list --upgradable' to see them.
Output hidden (5 lines)
Server
$ sudo apt install -y nginxInstalling:  nginx Installing dependencies:  nginx-common Suggested packages:  fcgiwrap  nginx-doc  ssl-cert Summary:[… 37 lines not shown …]
Output hidden (11 lines)
Server
$ nginx -vnginx version: nginx/1.28.3 (Ubuntu)
Output hidden (1 line)

Step 2: Check that it is running

The install started Nginx and set it to start at every boot (enabled):

Server
$ systemctl status nginx --no-pager● nginx.service - A high performance web server and a reverse proxy server     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)     Active: active (running) since Wed 2026-11-18 22:48:19 UTC; 6s ago Invocation: 48ba5fe31af94953897699ede3b10128       Docs: man:nginx(8)    Process: 3123 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)    Process: 3124 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)   Main PID: 3154 (nginx)      Tasks: 3 (limit: 1486)     Memory: 3M (peak: 7M)        CPU: 36ms     CGroup: /system.slice/nginx.service             ├─3154 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"             ├─3157 "nginx: worker process"             └─3158 "nginx: worker process"
Output hidden (15 lines)

Ask it for the page from the server itself. 200 OK means it works:

Server
$ curl -I http://localhostHTTP/1.1 200 OKServer: nginx/1.28.3 (Ubuntu)Date: Wed, 18 Nov 2026 22:48:26 GMTContent-Type: text/htmlContent-Length: 615Last-Modified: Wed, 18 Nov 2026 22:48:18 GMTConnection: keep-aliveETag: "6afe2b32-267"Accept-Ranges: bytes
Output hidden (9 lines)

Step 3: Open the firewall and load the page

With ufw on, a browser on another machine gets no answer yet: ufw drops the request. On Ubuntu 26.04, installing Nginx added four firewall profiles:

Server
$ sudo ufw app listAvailable applications:  Nginx Full  Nginx HTTP  Nginx HTTPS  Nginx QUIC  OpenSSH
Output hidden (6 lines)

Nginx HTTP opens port 80, Nginx HTTPS port 443, and Nginx Full both. Use Nginx Full, so HTTPS works later without another change:

Server
$ sudo ufw app info 'Nginx Full'Profile: Nginx FullTitle: Web Server (Nginx, HTTP + HTTPS)Description: Small, but very powerful and efficient web server Ports:  80,443/tcp
Output hidden (6 lines)

Nginx QUIC is new in 26.04: the same TCP ports plus UDP port 443, which HTTP/3 uses. You need it only once you turn on HTTP/3, which this page does not:

Server
$ sudo ufw app info 'Nginx QUIC'Profile: Nginx QUICTitle: Web Server (Nginx, HTTP + HTTPS + QUIC)Description: Small, but very powerful and efficient web server Ports:  80,443/tcp  443/udp
Output hidden (7 lines)
On Ubuntu 24.04

On 24.04 there are three profiles, with no Nginx QUIC:

Server
$ sudo ufw app listAvailable applications:  Nginx Full  Nginx HTTP  Nginx HTTPS  OpenSSH
Output hidden (5 lines)
Server
$ sudo ufw allow 'Nginx Full'Rule addedRule added (v6)
Output hidden (2 lines)
Server
$ sudo ufw statusStatus: active To                         Action      From--                         ------      ----OpenSSH                    ALLOW       AnywhereNginx Full                 ALLOW       AnywhereOpenSSH (v6)               ALLOW       Anywhere (v6)Nginx Full (v6)            ALLOW       Anywhere (v6)
Output hidden (8 lines)

Now open http://<server address>/ in a browser on your computer. You should see the default page with the heading “Welcome to nginx!” (mark 3):

The default Nginx page in a browser, its heading “Welcome to nginx!” marked 3
The default page, loaded from another machine through the firewall in the test run.

Step 4: Put your own page in place

The default site serves files from /var/www/html:

Server
$ ls /var/www/htmlindex.nginx-debian.html
Output hidden (1 line)

Nginx looks for index.html before the Debian welcome page, so a file of that name replaces it. No reload is needed for a new file:

Server
$ echo '<h1>It works</h1>' | sudo tee /var/www/html/index.html<h1>It works</h1>
Output hidden (1 line)
Server
$ curl http://localhost<h1>It works</h1>
Output hidden (1 line)

Step 5: Change the config without taking the site down

A config change needs two commands: sudo nginx -t to test the files, then sudo systemctl reload nginx to load them. As an example, stop Nginx from telling every visitor its version. On Ubuntu 26.04 the setting is already in /etc/nginx/nginx.conf, turned on with the value build, which sends the version:

Server
$ grep -n 'server_tokens' /etc/nginx/nginx.conf22:	server_tokens build; # Recommended practice is to turn this off
Output hidden (1 line)

Change build to off (or edit the line with sudo nano /etc/nginx/nginx.conf):

Server
$ sudo sed -i 's/server_tokens build;/server_tokens off;/' /etc/nginx/nginx.conf
On Ubuntu 24.04

On 24.04 the line is there but commented out, so the edit above changes nothing. Remove the # instead:

Server
$ grep -n 'server_tokens' /etc/nginx/nginx.conf21:	# server_tokens off;
Output hidden (1 line)
Server
$ sudo sed -i 's/# server_tokens off;/server_tokens off;/' /etc/nginx/nginx.conf
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

The Server line no longer shows the version:

Server
$ curl -I http://localhostHTTP/1.1 200 OKServer: nginxDate: Wed, 18 Nov 2026 22:48:38 GMTContent-Type: text/htmlContent-Length: 18Last-Modified: Wed, 18 Nov 2026 22:48:36 GMTConnection: keep-aliveETag: "6afe2b44-12"Accept-Ranges: bytes
Output hidden (9 lines)

Why reload and never restart

In the test the ; was then deleted from that line, as a typo. nginx -t names the file and the line (27 on 26.04, 26 on 24.04):

Server
$ sudo nginx -t2026/11/18 22:48:39 [emerg] 4864#4864: invalid number of arguments in "server_tokens" directive in /etc/nginx/nginx.conf:27nginx: configuration file /etc/nginx/nginx.conf test failed
Output hidden (2 lines)

A reload with the broken file fails, but Nginx keeps running on the config it had, so the site stays up:

Server
$ sudo systemctl reload nginxJob for nginx.service failed.See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
Output hidden (2 lines)
Server
$ curl -I http://localhostHTTP/1.1 200 OKServer: nginxDate: Wed, 18 Nov 2026 22:48:40 GMTContent-Type: text/htmlContent-Length: 18Last-Modified: Wed, 18 Nov 2026 22:48:36 GMTConnection: keep-aliveETag: "6afe2b44-12"Accept-Ranges: bytes
Output hidden (9 lines)

A restart stops Nginx first, then cannot start it again. The site is down:

Server
$ sudo systemctl restart nginxJob for nginx.service failed because the control process exited with error code.See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
Output hidden (2 lines)
Server
$ curl -I http://localhostcurl: (7) Failed to connect to localhost port 80 after 0 ms: Could not connect to server
Output hidden (1 line)

With the ; back, the test passes, and Nginx starts:

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 start nginx
Server
$ nginx -t2026/11/18 22:48:38 [warn] 4703#4703: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1nginx: the configuration file /etc/nginx/nginx.conf syntax is ok2026/11/18 22:48:38 [emerg] 4703#4703: open() "/run/nginx.pid" failed (13: Permission denied)nginx: configuration file /etc/nginx/nginx.conf test failed
Output hidden (4 lines)

Where the logs are

Every request is a line in /var/log/nginx/access.log: the visitor’s address, the time, the request, the status code, the size and the browser. Errors go to /var/log/nginx/error.log. Both need sudo:

Server
$ sudo tail -n 3 /var/log/nginx/access.log::1 - - [18/Nov/2026:22:48:40 +0000] "HEAD / HTTP/1.1" 200 0 "-" "curl/8.18.0"203.0.113.1 - - [18/Nov/2026:22:48:40 +0000] "GET / HTTP/1.1" 200 18 "-" "curl/8.5.0"203.0.113.1 - - [18/Nov/2026:22:48:42 +0000] "GET / HTTP/1.1" 200 18 "-" "curl/8.5.0"
Output hidden (3 lines)
Server
$ tail -n 3 /var/log/nginx/access.logtail: cannot open '/var/log/nginx/access.log' for reading: Permission denied
Output hidden (1 line)

When Nginx will not start, the reason is in the journal:

Server
$ sudo journalctl -u nginx -n 4 --no-pager -qNov 18 22:48:41 web-server systemd[1]: nginx.service: Failed with result 'exit-code'.Nov 18 22:48:41 web-server systemd[1]: Failed to start nginx.service - A high performance web server and a reverse proxy server.Nov 18 22:48:42 web-server systemd[1]: Starting nginx.service - A high performance web server and a reverse proxy server...Nov 18 22:48:42 web-server systemd[1]: Started nginx.service - A high performance web server and a reverse proxy server.
Output hidden (4 lines)

After a reboot

Nginx and the firewall rule both come back by themselves:

Server
$ sudo reboot
Server
$ systemctl is-active nginxactive
Output hidden (1 line)

“bind() to 0.0.0.0:80 failed (98: Address already in use)”

Another program has port 80, so Nginx cannot start. On a server that ran Apache before, it is usually Apache. The start fails:

Server
$ sudo systemctl start nginxJob for nginx.service failed because the control process exited with error code.See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
Output hidden (2 lines)
Server
$ sudo journalctl -u nginx -n 5 --no-pager -qNov 18 22:49:04 web-server nginx[1819]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)Nov 18 22:49:04 web-server nginx[1819]: nginx: [emerg] still could not bind()Nov 18 22:49:04 web-server systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURENov 18 22:49:04 web-server systemd[1]: nginx.service: Failed with result 'exit-code'.Nov 18 22:49:04 web-server systemd[1]: Failed to start nginx.service - A high performance web server and a reverse proxy server.
Output hidden (5 lines)

See which program holds the port. In the test it was a small Python web server:

Server
$ sudo ss -ltnp 'sport = :80'State     Recv-Q    Send-Q        Local Address:Port         Peer Address:Port    ProcessLISTEN    0         5                   0.0.0.0:80                0.0.0.0:*        users:(("python3",pid=1734,fd=3))
Output hidden (2 lines)

Stop that program, or move it to another port, then start Nginx. For Apache: sudo systemctl disable --now apache2.

Server
$ sudo systemctl start nginx

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): two packages (nginx, nginx-common), one service enabled at boot (nginx.service), port 80 now listening on IPv4 and IPv6, 26 files added in /etc (the Nginx config, its logrotate and init files, and the ufw profile file), and the two ufw rule files changed. The disk holds about 220 MB more on 26.04 and 240 MB on 24.04, but apt counts Nginx itself at under 2 MB; the rest is the package lists apt update downloads, and logs.

Ubuntu 26.04 vs 24.04: what changed

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
ufw0.36.2-9build10.36.2-6
server_tokens in /etc/nginx/nginx.confon, as server_tokens build; (line 22): the version is sentcommented out, # server_tokens off; (line 21): the version is sent
The edit that hides the versionsed -i 's/server_tokens build;/server_tokens off;/'sed -i 's/# server_tokens off;/server_tokens off;/'
ufw profiles the package addsfour: Nginx Full, Nginx HTTP, Nginx HTTPS, and Nginx QUIC (adds 443/udp)three: Nginx Full, Nginx HTTP, Nginx HTTPS
The line nginx -t names for the typonginx.conf:27nginx.conf:26
apt install outputapt 3: Installing: list and a Summary: blockapt 2: The following NEW packages will be installed:
systemctl status nginxadds an Invocation: lineno Invocation: line
curl when nothing listens on port 80Could not connect to serverCouldn’t connect to server
ProofRun log, 51 checks passedRun log, 50 checks passed

Uninstall Nginx

Close the firewall first. The Nginx Full profile is removed with Nginx, and ufw can then no longer find it by name:

Server
$ sudo ufw delete allow 'Nginx Full'Rule deletedRule deleted (v6)
Output hidden (2 lines)
Server
$ sudo apt remove -y nginxThe following package was automatically installed and is no longer required:  nginx-commonUse 'sudo apt autoremove' to remove it. REMOVING:  nginx Summary:  Upgrading: 0, Installing: 0, Removing: 1, Not Upgrading: 23  Freed space: 1631 kB  (Reading database ... 91556 files and directories currently installed.)Removing nginx (1.28.3-2ubuntu1.12) ...Processing triggers for man-db (2.13.1-1build1) ...
Output hidden (15 lines)

remove stops Nginx but leaves nginx-common (apt says it is no longer required) and your config in /etc/nginx, so a reinstall picks it up again.

Server
$ dpkg -l 'nginx*' | grep ^iiii  nginx-common   1.28.3-2ubuntu1.12 all          small, powerful, scalable web/proxy server - common files
Output hidden (1 line)
Server
$ ls /etc/nginxconf.d        fastcgi_params  koi-win     modules-available  nginx.conf    scgi_params      sites-enabled  uwsgi_paramsfastcgi.conf  koi-utf         mime.types  modules-enabled    proxy_params  sites-available  snippets       win-utf
Output hidden (2 lines)

To delete the config and the logs as well, purge nginx-common:

Server
$ sudo apt purge -y nginx-common[… 11 lines not shown …]Purging configuration files for nginx-common (1.28.3-2ubuntu1.12) ...Processing triggers for ufw (0.36.2-9build1) ...Rules updated for profile 'OpenSSH'Skipped reloading firewall
Output hidden (5 lines)
Server
$ ls /etc/nginx /var/log/nginxls: cannot access '/etc/nginx': No such file or directoryls: cannot access '/var/log/nginx': No such file or directory
Output hidden (2 lines)

Your pages in /var/www/html are not touched. Delete them yourself if you no longer need them:

Server
$ ls /var/www/htmlindex.html  index.nginx-debian.html
Output hidden (1 line)