If you’re looking to set up Nginx on Red Hat, Rocky Linux, AlmaLinux, or Oracle Linux, you’ve come to the right place! This guide provides easy, step-by-step instructions for both the stable and mainline versions of Nginx.
Step 1: Choose Your Version of Nginx
Nginx offers two primary versions:
- Stable Version: Suitable for production environments, offering a slower release cycle with fewer updates.
Latest Stable Version (as of today):1.26.2
- Mainline Version: Contains the latest features and bug fixes, ideal for testing or development environments.
Latest Mainline Version (as of today):1.27.1
Step 2: Install Prerequisites
Before installing Nginx, update your system packages:
sudo dnf update -y
Then, install the necessary dependencies:
sudo dnf install -y dnf-utils
Step 3: Set Up the Nginx Repository
For Stable Version:
To set up the repository for the stable version of Nginx, create a repository file:
sudo tee /etc/yum.repos.d/nginx.repo << 'EOF'
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
For Mainline Version:
For the mainline version, use the following repository configuration:
sudo tee /etc/yum.repos.d/nginx.repo << 'EOF'
[nginx-mainline]
name=nginx mainline repo
baseurl=https://nginx.org/packages/mainline/rhel/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
Step 4: Install Nginx
With the repository set up, you can install Nginx. Run the following command:
sudo dnf install -y nginx
Step 5: Start and Enable Nginx Service
To start Nginx and ensure it runs on system boot, execute:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 6: Verify the Installation
Check if Nginx is running properly:
sudo systemctl status nginx
You should see an output indicating that Nginx is active and running.
Step 7: Allow Nginx Through the Firewall
To make Nginx accessible, allow HTTP and HTTPS traffic through the firewall:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload<br>
Step 8: Test Nginx
Open your web browser and navigate to your server’s IP address. If Nginx is correctly installed, you should see the default Nginx welcome page.
Conclusion
Congratulations! You have successfully installed Nginx on Red Hat, Rocky Linux, AlmaLinux, or Oracle Linux. Whether you chose the stable or mainline version, you now have a powerful web server up and running!