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
$ 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.$ sudo apt install -y nginxInstalling: nginx Installing dependencies: nginx-common Suggested packages: fcgiwrap nginx-doc ssl-cert Summary:[… 37 lines not shown …]$ nginx -vnginx version: nginx/1.28.3 (Ubuntu)Step 2: Check that it is running
The install started Nginx and set it to start at every boot (enabled):
$ 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"Ask it for the page from the server itself. 200 OK means it works:
$ 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: bytesStep 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:
$ sudo ufw app listAvailable applications: Nginx Full Nginx HTTP Nginx HTTPS Nginx QUIC OpenSSHNginx HTTP opens port 80, Nginx HTTPS port 443, and Nginx Full both. Use Nginx Full, so HTTPS works later without another change:
$ 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/tcpNginx 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:
$ 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/udpOn Ubuntu 24.04
On 24.04 there are three profiles, with no Nginx QUIC:
$ sudo ufw app listAvailable applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH$ sudo ufw allow 'Nginx Full'Rule addedRule added (v6)$ sudo ufw statusStatus: active To Action From-- ------ ----OpenSSH ALLOW AnywhereNginx Full ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)Nginx Full (v6) ALLOW Anywhere (v6)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):

Step 4: Put your own page in place
The default site serves files from /var/www/html:
$ ls /var/www/htmlindex.nginx-debian.htmlNginx 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:
$ echo '<h1>It works</h1>' | sudo tee /var/www/html/index.html<h1>It works</h1>$ curl http://localhost<h1>It works</h1>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:
$ grep -n 'server_tokens' /etc/nginx/nginx.conf22: server_tokens build; # Recommended practice is to turn this offChange build to off (or edit the line with sudo nano /etc/nginx/nginx.conf):
$ sudo sed -i 's/server_tokens build;/server_tokens off;/' /etc/nginx/nginx.confOn Ubuntu 24.04
On 24.04 the line is there but commented out, so the edit above changes nothing. Remove the # instead:
$ grep -n 'server_tokens' /etc/nginx/nginx.conf21: # server_tokens off;$ sudo sed -i 's/# server_tokens off;/server_tokens off;/' /etc/nginx/nginx.conf$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful$ sudo systemctl reload nginxThe Server line no longer shows the version:
$ 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: bytesWhy 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):
$ 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 failedA reload with the broken file fails, but Nginx keeps running on the config it had, so the site stays up:
$ sudo systemctl reload nginxJob for nginx.service failed.See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.$ 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: bytesA restart stops Nginx first, then cannot start it again. The site is down:
$ 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.$ curl -I http://localhostcurl: (7) Failed to connect to localhost port 80 after 0 ms: Could not connect to serverWith the ; back, the test passes, and Nginx starts:
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful$ sudo systemctl start nginx$ 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 failedWhere 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:
$ 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"$ tail -n 3 /var/log/nginx/access.logtail: cannot open '/var/log/nginx/access.log' for reading: Permission deniedWhen Nginx will not start, the reason is in the journal:
$ 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.After a reboot
Nginx and the firewall rule both come back by themselves:
$ sudo reboot$ systemctl is-active nginxactive“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:
$ 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.$ 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.See which program holds the port. In the test it was a small Python web 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))Stop that program, or move it to another port, then start Nginx. For Apache: sudo systemctl disable --now apache2.
$ sudo systemctl start nginxWhat 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
| What | Ubuntu 26.04 | Ubuntu 24.04 |
|---|---|---|
| System | Ubuntu 26.04.1 LTS7.0.0-43-generic | Ubuntu 24.04.5 LTS6.8.0-147-generic |
| nginx | 1.28.3-2ubuntu1.12 | 1.24.0-2ubuntu7.19 |
| nginx-common | 1.28.3-2ubuntu1.12 | 1.24.0-2ubuntu7.19 |
| ufw | 0.36.2-9build1 | 0.36.2-6 |
server_tokens in /etc/nginx/nginx.conf | on, as server_tokens build; (line 22): the version is sent | commented out, # server_tokens off; (line 21): the version is sent |
| The edit that hides the version | sed -i 's/server_tokens build;/server_tokens off;/' | sed -i 's/# server_tokens off;/server_tokens off;/' |
| ufw profiles the package adds | four: 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 typo | nginx.conf:27 | nginx.conf:26 |
apt install output | apt 3: Installing: list and a Summary: block | apt 2: The following NEW packages will be installed: |
systemctl status nginx | adds an Invocation: line | no Invocation: line |
| curl when nothing listens on port 80 | Could not connect to server | Couldn’t connect to server |
| Proof | Run log, 51 checks passed | Run 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:
$ sudo ufw delete allow 'Nginx Full'Rule deletedRule deleted (v6)$ 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) ...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.
$ dpkg -l 'nginx*' | grep ^iiii nginx-common 1.28.3-2ubuntu1.12 all small, powerful, scalable web/proxy server - common files$ 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-utfTo delete the config and the logs as well, purge nginx-common:
$ 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$ ls /etc/nginx /var/log/nginxls: cannot access '/etc/nginx': No such file or directoryls: cannot access '/var/log/nginx': No such file or directoryYour pages in /var/www/html are not touched. Delete them yourself if you no longer need them:
$ ls /var/www/htmlindex.html index.nginx-debian.html