Nginx (short for Engine X) is a free and open-source webserver. It is a high-performance HTTP server and reverse proxy. Nginx is also used as a load balancer, HTTP cache, and mail proxy.
Nginx gives the best performance for high traffic websites - get the benefit of low memory usage and high concurrency.
In this tutorial, we learn how to install Nginx on Rocky Linux 8.
Step 1: Install Nginx on Rocky Linux 8
First, update all the available packages on Rocky Linux.
$ sudo dnf upgrade
Note: dnf update is a deprecated alias.
Now, install Nginx on Rocky Linux.
$ sudo dnf install nginx
Once Nginx is installed, start the Nginx service.
$ sudo systemctl start nginx
If any issues it will display an error message or else no output.
To verify the status of the Nginx service, type:
$ sudo systemctl status nginx
Now make sure to enable Nginx at the start at boot time.
$ sudo systemctl enable nginx
To check the Nginx version which is installed, type:
$ nginx -v
nginx version: nginx/1.14.1
The output shows we have installed Nginx 1.14.1 version. The main configuration file is stored under the directory /etc/nginx and the main config file is /etc/nginx/nginx.conf. The Nginx log files are stored at /var/log/nginx.
Step 2: Setup Firewall
To allow HTTP and HTTPS traffic (when using SSL) on the firewall.
$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
To make the changes effective, reload the firewall service:
$ sudo firewall-cmd --reload
You can verify by listing the current firewall settings:
$ sudo firewall-cmd --permanent --list-all
Step 3: Verify the installation
Open a browse and enter server IP or domain name to see the Nginx default page on Rocky Linux.
On Rocky Linux, the default Nginx webpage is located in /usr/share/nginx/html.
To completely uninstall Nginx on Rocky Linux, type
$ sudo dnf remove nginx
Then manually delete the Nginx log files.
$ sudo rm -rf /var/log/nginx
In this tutorial, we learned how to install Nginx on Rocky Linux 8. Also checked how to verify Nginx installation.