Guides 11792 Published by

This article walks Rocky Linux 9 users through a clean way to install or upgrade to either the stable or mainline build of nginx by first removing any legacy packages that might conflict with RHEL or EPEL. It then shows how to add the official nginx repository via a small repo file that automatically expands the release version and includes module hotfixes, and optionally adds a separate mainline repo for the bleeding‑edge 1.27.x series. Installation commands are provided for both builds, along with troubleshooting tips such as updating openssl when dependency errors arise and instructions to verify the service is running correctly. Finally, the guide explains why keeping the nginx repo in its own file protects your settings from being overwritten by Rocky Extras during system upgrades.



Install/Upgrade Nginx Mainline/Stable on Rocky Linux 9 – A Quick‑Start Guide

If you’re running a web service on Rocky Linux 9 and you want the latest stable or bleeding‑edge version of nginx, this article shows you how to get it without wrestling with broken dependencies.

1. Clean up any old nginx first
sudo dnf remove nginx*

Why bother? Old packages from RHEL or EPEL can clash with the official repo and leave you with a half‑broken installation. I’ve seen servers that started throwing “conflicting requests” just because a stale nginx-1.14 was still lurking.

2. Enable the official nginx repository
sudo dnf install -y dnf-plugins-core

cat <<EOF | sudo tee /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/rhel/\$releasever/\$basearch/
enabled=1
gpgcheck=1
module_hotfixes=true
gpgkey=https://nginx.org/keys/nginx_signing.key
EOF

The \$releasever variable expands to 9 on Rocky 9, so you don’t have to edit the file manually. The module_hotfixes=true line is a nice touch that keeps minor patches from slipping through.

3. Optional: Add the mainline repo

If you want the cutting‑edge release (currently 1.27.x), add another section:

cat <<EOF | sudo tee /etc/yum.repos.d/nginx-mainline.repo
[nginx-mainline]
name=nginx mainline
baseurl=https://nginx.org/packages/mainline/rhel/\$releasever/\$basearch/
enabled=1
gpgcheck=1
module_hotfixes=true
gpgkey=https://nginx.org/keys/nginx_signing.key
EOF

You can keep both repos enabled if you like, but only the package in your install command will win out.

4. Install or upgrade nginx

To install the stable build:

sudo dnf install -y nginx

To switch to mainline (or stay on mainline if it’s already enabled):

sudo dnf install -y --enablerepo=nginx-mainline nginx

dnf will pull the newest 1.27.x version and resolve any dependency quirks automatically.

5. Verify everything is running
systemctl status nginx

You should see Active: active (running) and a line that says something like “nginx version: nginx/1.27.x”.

If you hit a hiccup, the most common culprit on Rocky 9 is an old openssl package that doesn’t satisfy the new binary’s requirements. The fix is usually just:

sudo dnf update openssl*
6. Keep it up to date

For stable:

sudo dnf upgrade nginx

For mainline (if you have both repos enabled, specify which one):

sudo dnf upgrade --enablerepo=nginx-mainline nginx

That’s all there is to it. No more manual RPM juggling.

If you’re curious why I keep this repo in a separate file instead of editing /etc/yum.repos.d/nginx.repo directly, it’s because Rocky 9 ships with a “Rocky‑Extras” that can overwrite your changes on an OS upgrade. A dedicated file keeps your settings safe.