How To Install NginX on CentOS 8

On this article we will discuss how to install Nginx on CentOS 8 operating system.


Beside Apache Web server, Nginx is one of the most popular web servers which is often used to handle the load of some of the largest sites on the Internet. Nginx pronounced “engine x” is an open-source, high-performance HTTP and reverse proxy server. It can be used as a standalone web server, load balancer, content cache, and reverse proxy for HTTP and non-HTTP servers.

Compared to Apache, Nginx can handle a much large number of concurrent connections and has a smaller memory footprint per connection. On this tutorial, we will learn how to install Nginx on CentOS 8 operating system.

Nginx installation on CentOS 8


Before we are starting Nginx installation on CentOS 8, we need to prepare our environment firest. Here are the prerequisite of Nginx installation on CentOS 8 :

  • CentOS 8 System with sufficient disk space
  • Non-root user with sudo privileges
  • Active firewall installed on your server
  • There is no Apache or any other process running on port 80 or 443

The Nginx installation process will be consisting of several steps as mentioned below :

A more detailed explanation will be described in the following sub-chapters.

1. Install NginX Web Server on CentOS 8

In order to install Nginx on CentOS 8, we’ll use the dnf package manager, which is the new default package manager on CentOS 8.

$ sudo dnf install nginx

Output :

[ramans@localhost ~]$ sudo dnf install nginx
CentOS-8 - AppStream                                                      43 kB/s | 5.8 MB     02:17    
CentOS-8 - Base                                                          168 kB/s | 2.2 MB     00:13    
CentOS-8 - Extras                                                        1.4 kB/s | 8.1 kB     00:05    
Dependencies resolved.
 Package                        Arch      Version                                     Repository    Size
 nginx                          x86_64    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream    570 k
Installing dependencies:
 nginx-all-modules              noarch    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     23 k
 nginx-filesystem               noarch    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     24 k
 nginx-mod-http-image-filter    x86_64    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     35 k
 nginx-mod-http-perl            x86_64    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     45 k
 nginx-mod-http-xslt-filter     x86_64    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     33 k
 nginx-mod-mail                 x86_64    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     64 k
 nginx-mod-stream               x86_64    1:1.14.1-9.module_el8.0.0+184+e34fea82      AppStream     85 k
Enabling module streams:
 nginx                                    1.14                                                          

Transaction Summary
Install  8 Packages

Total download size: 881 k
Installed size: 2.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): nginx-filesystem-1.14.1-9.module_el8.0.0+184+e34fea82.noarch.rpm  3.3 kB/s |  24 kB     00:07    
(2/8): nginx-all-modules-1.14.1-9.module_el8.0.0+184+e34fea82.noarch.rpm 3.1 kB/s |  23 kB     00:07    
(3/8): nginx-mod-http-image-filter-1.14.1-9.module_el8.0.0+184+e34fea82. 123 kB/s |  35 kB     00:00    
(4/8): nginx-mod-http-perl-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64.r 115 kB/s |  45 kB     00:00    
(5/8): nginx-mod-http-xslt-filter-1.14.1-9.module_el8.0.0+184+e34fea82.x 117 kB/s |  33 kB     00:00    
(6/8): nginx-mod-mail-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64.rpm    2.3 kB/s |  64 kB     00:27    
(7/8): nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64.rpm              16 kB/s | 570 kB     00:35    
(8/8): nginx-mod-stream-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64.rpm  3.0 kB/s |  85 kB     00:28    
Total                                                                     23 kB/s | 881 kB     00:37  
. . .


After the installation is finished, we have to enable and start the Nginx service, by submitting following command line :

$ sudo systemctl enable nginx
$ sudo systemctl start nginx
$ sudo systemctl status nginx

Output will be as shown below :

Enable and start Nginx Service on CentOS 8
Enable and start Nginx Service on CentOS 8

2. Adjusting Firewall Rules

On our system, we have enabled firewalld firewall, so we have to adjust the firewall settings in order to allow external connections on your Nginx web server, which runs on port 80 by default.

On this stage we will permanently enable HTTP connections on port 80. To perform this task, we will do the following command lines :

$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --list-all
$ sudo firewall-cmd --reload

Output :

[ramans@localhost ~]$ sudo firewall-cmd --permanent --add-service=http
[ramans@localhost ~]$ sudo firewall-cmd --permanent --list-all
  target: default
  icmp-block-inversion: no
  services: cockpit dhcpv6-client http ssh
  masquerade: no
  rich rules: 
[ramans@localhost ~]$ sudo firewall-cmd --reload
Adjusting Firewall Rule
Adjusting Firewall Rule

On current situation, our Nginx server is fully installed and ready to be accessed by external visitors.

3. Testing Web Server

Now, we can test our Nginx installation, by opening http://<ip_address_or_hostname> in web browser. You should see the default Nginx welcome page, which should look like the image below.

Nginx web server is now correctly installed on our CentOS 8
Nginx web server is now correctly installed on our CentOS 8


In this short tutorial, we’ve learnt how to install and set up Nginx, a high-performance web server and reverse proxy. I hope this article would be helpful.

Add a Comment

Your email address will not be published. Required fields are marked *