How to Install the Latest Nginx Mainline on Rocky Linux 9 and 8
If you’ve been using the stock EPEL build of Nginx, you’re probably stuck on an old version that doesn’t support TLS‑v1.3 or the latest HTTP/2 tweaks. The official Nginx “Mainline” release gives you those goodies plus faster performance in some cases. This guide walks you through getting that exact package onto Rocky Linux 8 (EL8) and 9 (EL9).
Prerequisites
- A user with sudo privileges or root access.
- A clean installation of Rocky Linux 8 or 9, or at least a system that still runs the default distro packages.
Step 1: Clean Up Any Old Nginx Installations
sudo dnf remove nginx httpd -y
The stock nginx from EPEL is older than what we’ll install. If you leave it around, the system could end up running two different binaries with conflicting config files—like a house that’s half built and half demolished.
Step 2: Add the Official Nginx Repository
sudo dnf install -y https://nginx.org/packages/centos/RHEL-$(rpm -E %rhel)/nginx.repo
This pulls in the official repo file. On EL9 it will point to RHEL-9, on EL8 to RHEL-8. The repo contains the mainline build that we want.
Step 3: Enable the Mainline Module Stream (Only for EL8)
Rocky Linux 8 uses module streams for some packages. If you’re on EL8, make sure you’re pulling the right stream:
sudo dnf config-manager --set-enabled powertools
The powertools repo is where Nginx lives on EL8; it’s a hidden gem that many people forget to enable.
Step 4: Install the Mainline Package
sudo dnf install -y nginx
That single command pulls in the latest mainline build for your OS version. If you’re on EL9, you’ll see nginx-1.26.x or whatever the current release is. On EL8 it will pull the same version but with EL8‑compatible binaries.
Step 5: Verify It’s the Mainline Build
nginx -v
You should see something like:
nginx version: nginx/1.26.0 (mainline)
If you still see “stable” in the output, you’re not actually running mainline—double‑check that you didn’t pull a different repo or an older cached package.
Step 6: Enable and Start the Service
sudo systemctl enable --now nginx
The --now flag starts it immediately. If you get errors, run journalctl -xe | grep nginx to see why—often it’s a config file syntax error or missing TLS certs.
Step 7: Test Your Installation
Open your browser and point it at your server’s IP (or a local test domain). You should see the default Nginx “Welcome” page. If you want to confirm TLS‑v1.3 is working, run:
openssl s_client -connect localhost:443 -tls1_3
You should see Protocol : TLSv1.3 in the output.
Gotchas
- Conflicting Ports: If Apache (httpd) or another web server was left running, you’ll get a “Address already in use” error. Make sure to stop or disable those services.
- SELinux: On some systems SELinux blocks Nginx from reading certain directories. Use setsebool -P httpd_can_network_connect 1 if you run into network errors, or check the audit log for AVC denials.
That’s it—your Rocky Linux machine is now rocking the latest Nginx Mainline build with all its newest features.