Skip to main content

Web servers and networking · Beginner · 10 min

How to Install Nginx on Ubuntu 26.04

By Padding · Updated 15 Nov 2026
Ubuntu 26.04.1 LTS · Nginx 1.30 stable (nginx.org repo)

You will install the current stable Nginx 1.30 from the official nginx.org repository on Ubuntu 26.04, serve its test page, and learn where its files live and how to reload it safely.

On this page

Nginx is the web server behind a large share of the internet. It serves files, passes requests to apps and terminates HTTPS. You can install it from Ubuntu's own archive or from the repository the Nginx project runs. This tutorial uses the project's repository, so you get the current stable release, Nginx 1.30, rather than the older version in the Ubuntu archive. Ubuntu 26.04's own package is an older 1.28 release.

In this tutorial you will add the repository, check its signing key, install Nginx, start it, and find your way around its files. It is the fourth tutorial in the series Your first production server.

Step 1 · Add the nginx.org repository

Install the tools needed to fetch and verify the repository key:

Bash
sudo apt-get update
sudo apt-get install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring

Download the Nginx signing key and store it where apt can find it:

Bash
curl -fsSL https://nginx.org/keys/nginx_signing.key \
  | gpg --dearmor \
  | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg > /dev/null

Check that the key is the real one. Print its fingerprints. GnuPG needs its settings folder to exist first, so create it:

Bash
mkdir -p -m 700 ~/.gnupg
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

The file holds two signing keys. The output must include these two fingerprint lines, one under each pub line (compare them with the ones on nginx.org/en/linux_packages.html):

Text
pub   rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <signing-key@nginx.com>

pub   rsa4096 2024-05-29 [SC]
      9E9BE90EACBCDE69FE9B204CBCDCD8A38D88A2B3
uid                      nginx signing key <signing-key-3@nginx.com>

If either differs, delete the key file and stop. The 2011 key expires in May 2027, so on a later date its expires line will differ. The fingerprint is what matters.

Now add the repository for the stable branch. lsb_release -cs prints your release code name, which is resolute on Ubuntu 26.04.

Bash
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" \
  | sudo tee /etc/apt/sources.list.d/nginx.list

The line above uses the stable packages. The project also publishes a mainline branch, with newer features and less testing, under https://nginx.org/packages/mainline/ubuntu. Stay on stable for a production server.

If Ubuntu's own nginx package is also visible, apt may prefer it. Tell apt to prefer the nginx.org package:

Bash
printf 'Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n' \
  | sudo tee /etc/apt/preferences.d/99nginx

Check it worked

Bash
sudo apt-get update
apt-cache policy nginx

The Candidate line shows a 1.30.x version ending in ~resolute, and the table below it shows https://nginx.org/packages/ubuntu resolute/nginx as the source.

Step 2 · Install Nginx

Bash
sudo apt-get install -y nginx
nginx -v

The last command prints nginx version: nginx/1.30.x.

The package starts Nginx and enables it at boot when it is installed. Confirm with:

Bash
systemctl status nginx

You want Active: active (running). If it is not running, use sudo systemctl enable --now nginx.

Check the configuration at any time with nginx -t:

Bash
sudo nginx -t

nginx -t tests the configuration files without touching the running server. It ends with syntax is ok and test is successful.

Step 3 · Open the test page

Ask Nginx for its default page from the server itself:

Bash
curl -sI http://localhost/ | head -n 1
curl -s http://localhost/ | grep -o '<title>.*</title>'

The first command prints HTTP/1.1 200 OK and the second prints <title>Welcome to nginx!</title>.

Check it worked

From your own computer, open http://your_server_ip/ in a browser. You see the same page. If the page does not load, the cause is a firewall. On Ubuntu with UFW enabled, allow web traffic:

Bash
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status

The nginx.org package does not register a UFW application profile, so open the ports by number. Many cloud providers also have their own firewall in their dashboard. Open the ports there too.

Troubleshooting

  • bind() to 0.0.0.0:80 failed (98: Address already in use): another program holds port 80, often Apache. Find it with sudo ss -ltnp 'sport = :80'.
  • E: Unable to locate package nginx or a 404 from nginx.org on apt update: check /etc/apt/sources.list.d/nginx.list. The word at the end of the line must be nginx, and the code name must be resolute.
  • NO_PUBKEY during apt update: the key file is missing or not readable. Repeat the download step.

Step 4 · Learn where things live

The nginx.org package uses these paths:

| Path | What it holds |
|---|---|
| /etc/nginx/nginx.conf | The main configuration |
| /etc/nginx/conf.d/*.conf | One file per site or app. This is where you add server blocks |
| /usr/share/nginx/html | The default web root with index.html |
| /var/log/nginx/access.log | One line per request |
| /var/log/nginx/error.log | Errors and warnings |

If you have used Nginx from Ubuntu's own package, note the difference: this package has no sites-available or sites-enabled folders. Put each site in its own file in /etc/nginx/conf.d/, ending in .conf.

Look at the default site:

Bash
cat /etc/nginx/conf.d/default.conf | grep -E 'listen|server_name|root'

It listens on port 80, answers to localhost and serves files from /usr/share/nginx/html.

Step 5 · Change a setting and reload safely

After you edit any configuration file, test it before you apply it. A syntax error found by nginx -t costs nothing. The same error found by a reload can leave the old configuration running, and a restart with a bad file takes the site down.

Make a small change, for example replace the page:

Bash
echo '<h1>Served by Nginx 1.30</h1>' | sudo tee /usr/share/nginx/html/index.html

Static file changes need no reload. Configuration changes do. To apply them without dropping connections:

Bash
sudo nginx -t && sudo systemctl reload nginx

Check it worked

Bash
curl -s http://localhost/

The page now shows <h1>Served by Nginx 1.30</h1>.

Next steps

Nginx is installed and serving a page.

  • Serve more than one domain from this server: /tutorials/host-multiple-sites-with-nginx-server-blocks.
  • Turn on HTTPS: /tutorials/free-https-with-lets-encrypt-and-nginx.
  • Forward requests to an app: /tutorials/nginx-reverse-proxy-for-a-node-app.
  • Set up the firewall properly: /tutorials/set-up-ufw-firewall-ubuntu-26-04.
  • The nginx.org install steps are at nginx.org/en/linux_packages.html.

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.