How to Install Nginx on CentOS/Redhat
- Last updated: Nov 3, 2023
- Views: 366
- Author: Admin

Hello colleagues.
The Nginx web server is one of the most powerful and popular web servers in the world, which today powers a number of the largest sites with huge traffic. Nginx can serve very large sites with high traffic and consumes less resources of the physical server itself than Apache.
In this article, we'll show you how to install an Nginx ver server on CentOS 8. When installing Nginx, you need to have sudo privileges or install as root.
The content of the article:
- Nginx installation.
- Starting the Nginx web server.
- Automatic start of Nginx.
- Firewall configuration.
- Checking the Nginx web server.
- Nginx process control.
1. Install Nginx.
The Nginx web server is available in the default Centos 8 repository, so we will be installing the Nginx web server using the default dnf package manager, which is the new default package manager available on CentOS 8. To install Nginx, run the following command in the console:
$. sudo dnf install nginx
Next you will be asked to confirm the installation, enter y. Once confirmed, the dnf package manager will install Nginx and all of its dependencies on your server.
2. Starting the Nginx web server.
After Nginx has been successfully installed, we now need to start it. To start Nginx, use the command:
$. sudo systemctl start nginx
3. Automatic start of Nginx.
When loading or restarting the server, the Nginx service itself does not start. Checking the status.
$. service nginx status
As you can see in the screenshot, the Nginx service has the Loaded - disabled parameter, which means that when the server restarts for some reason, your Nginx web server will not be active, and the site will also not work.
In order for Nginx to start every time after the server restarts, the Nginx service must be set to auto start, for this, use the command:
$. sudo systemctl enable nginx
Now let's check the status again.
$. service nginx status
Now the value of the Loaded parameter is enabled. Auto start will work.
4. Firewall configuration.
If you have an active Firewall on your server, then incoming traffic on ports 80 and 443 will be closed, and you will not be able to get access from the Internet to your site or application, so you need to open them. We can open access in two ways, the first is to open ports 80 and 443 themselves, and the second is to open the http and https protocols.
First option: Open access to the Nginx web server using the http and https protocols:
$. sudo firewall-cmd --permanent --add-service=http
$. sudo firewall-cmd --permanent --add-service=https
Second option: Open access to the Nginx web server on ports 80 and 443:
$. sudo firewall-cmd --permanent --add-port=80/tcp
$. sudo firewall-cmd --permanent --add-port=443/tcp
For our changes to take effect, you need to restart the Firewall service:
$. sudo firewall-cmd --reload
Check if access is open.
$. sudo firewall-cmd --permanent --list-all
Access is open.
5. Checking the Nginx web server.
Now it's the turn to check if our web server is working at all, for this we enter the ip address of our server in the browser and look. My address is 192.168.2.99
As you can see, the test page of the Nginx web server has successfully loaded, which means that everything is working correctly.
Thank you all, I hope my article was of some help to you.