In this tutorial, we will show you how to install Nginx Web Server on Rocky Linux 9. For those of you who didn’t know, Nginx (short for Engine X) is a free and open-source web server that serves as a reverse proxy, HTTP load balancer, and email proxy for IMAP, POP3, and SMTP. Thanks to its ability to handle massive numbers of connections, it is the preferred web server of many websites that deal with high traffic.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx web server on Rocky Linux. 9.
- A server running one of the following operating systems: Rocky Linux 9.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Nginx on Rocky Linux 9
Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:
sudo dnf check-update sudo dnf install dnf-utils
Step 2. Installing Nginx Web Server on Rocky Linux 9.
By default, Nginx is not available on Rocky Linux 9 base repository. Now run the following command below to add Nginx stable repository to your system:
sudo tee /etc/yum.repos.d/nginx-stable.repo<<EOF [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/9/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true EOF
Now, run the following command to install the latest stable version of Nginx to your server:
sudo dnf update sudo dnf install nginx
Once the installation is done, start the Nginx service and enable it to automatically start on reboot all in one go with:
sudo systemctl enable --now nginx
To verify that the latest version of Nginx has been installed, run:
Step 3. Configure Firewall.
By default, Nginx listens on ports 80 and 443. If any firewall is installed and configured on your server, then you will need to allow both ports via firewalld. You can allow them with the following command:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
You can verify by listing the current firewall settings:
sudo firewall-cmd --permanent --list-all
Step 4. Accessing Nginx Default Page.
Now, open your web browser and access the Nginx default page using the URL
http://your-server-ip-address. You should see the Nginx default page on Rocky Linux. :
You can also test that your web page is working from the command line with:
curl -I http://your-ip-address
Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx web server on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Nginx website.