Install Nginx on Rocky Linux 9 / AlmaLinux 9 (Official Stable)

From installation to production-ready deployment.

Back to Guides ยท Home

Applies to: Rocky Linux 9 / AlmaLinux 9

Goal: Install the latest stable Nginx from the official repository and configure firewall rules.

1. Update System and Install Prerequisites

sudo dnf update -y
sudo dnf install -y dnf-utils curl ca-certificates

2. Add Official Nginx YUM Repository

sudo tee /etc/yum.repos.d/nginx.repo >/dev/null <<'REPO'
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/9/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
REPO

3. Install Nginx

sudo dnf install -y nginx
nginx -v

4. Start and Enable Nginx

sudo systemctl enable --now nginx
sudo systemctl status nginx --no-pager

5. Configure Firewall (firewalld)

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services

6. Basic Availability Check

curl -I http://127.0.0.1
sudo ss -tulpen | grep ':80'

Visit http://your-server-ip in browser. If you see the Nginx welcome page, installation succeeded.

7. Common Management Commands

sudo nginx -t
sudo systemctl reload nginx
sudo systemctl restart nginx
sudo systemctl stop nginx

8. Important Paths