How to Install Nginx on CentOS/Redhat

  • Last update: Apr 3, 2024
  • Views: 34
  • Author: Admin
How to Install Nginx on CentOS/Redhat

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:

  1. Nginx installation.
  2. Starting the Nginx web server.
  3. Automatic start of Nginx.
  4. Firewall configuration.
  5. Checking the Nginx web server.
  6. 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

centos 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

centos install nginx

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

centos install nginx

Now let's check the status again.

$. service nginx status

centos install nginx

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

centos install nginx

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

centos install nginx

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

centos install nginx

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

centos install nginx

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.

SIMILAR ARTICLES

How to uninstall PHP on Centos 8
How to uninstall Apache on Centos 8
Installing Apache Web Server on CentOS 8