Installing Nginx on AlmaLinux 9: A Straight‑Forward Guide
You’ll learn how to add the official nginx repository, install the packages, get the daemon running, and confirm it’s serving pages—no guessing, no extra fluff.
1 . Verify EPEL is available
AlmaLinux ships with a minimal set of repos; for nginx you’ll need the Extra Packages for Enterprise Linux (EPEL) repo.
sudo dnf install -y epel-release
If that command fails, your system probably doesn’t have `dnf` or the network is blocked—fix those first before moving on.
2 . Add the official nginx repository
The upstream nginx repo keeps everything up‑to‑date and includes the latest security fixes.
sudo tee /etc/yum.repos.d/nginx.repo <<EOF [nginx] name=nginx repo baseurl=https://nginx.org/packages/centos/9/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key EOF
Why bother with a separate repo? Because the default `dnf` stream on AlmaLinux 9 only ships an old nginx‑1.14 package from the base repos—modern web apps need at least 1.20.
3 . Install the nginx packages
sudo dnf install -y nginx
That’s it. DNF pulls `nginx`, its dependencies, and a matching `systemd` unit file for you automatically.
If you see an error about “Package nginx‑x.y.z not available,” double‑check that the repo URL matches your arch (`x86_64` or `aarch64`) and that the GPG key was imported correctly.
4 . Enable and start the service
sudo systemctl enable --now nginx
Enabling guarantees it starts on boot, while `--now` brings it up immediately.
You can confirm its status with:
systemctl status nginx
If the output shows “active (running),” you’re good to go.
5 . Allow traffic through the firewall
AlmaLinux’s default firewalld blocks port 80/443 until you open it:
sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall‑cmd --reload
Skipping this step means a browser will hang on “This page can’t be reached” even though nginx is serving content.
6 . Test the default page
curl -I http://localhost
You should see a `200 OK` and `Server: nginx`. If you hit `403 Forbidden`, check that `/usr/share/nginx/html/index.html` exists and has the right permissions.
7 . Common pitfalls (and how I’ve seen them happen)
- Stale httpd package – I once ran a quick `dnf upgrade` on an older AlmaLinux 8 server, and nginx stopped serving because the old Apache (`httpd`) was still alive and listening on port 80. Kill it with `sudo systemctl stop httpd` or uninstall if you’re not using it.
- SELinux denial – If you’ve enabled SELinux in enforcing mode and your site files are outside `/usr/share/nginx/`, the daemon will refuse to read them. Either move the content or run `sudo restorecon -Rv /var/www/html`.
- Repository mismatch – Installing the “CentOS 9” repo on AlmaLinux can pull incompatible packages. Stick with the nginx.org repo we added above.
That’s the whole story—install, enable, firewalls, test. Give it a try and let me know if you hit any snags.