November 24, 2020
How to Install Nginx On CentOS 8

How To Install Nginx on CentOS 8

On this article we will discuss how to install NginX on CentOS 8 and configuring firewall for HTTP port.

Introduction

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. On this article we will learn how to install NginX on CentOS linux operating system.

For uninstalling/removing Nginx from CentOS system tutorial has been discussed on How to Unistall Nginx from Centos 7 article.

Prerequisites

To install NginX on CentOS 8, then we have to fulfill the prerequisites, as mentioned below :

  • 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

Installing Nginx Web Server

The Nginx package is available in the default CentOS repositories, so we don’t need to add it to the repository first. The installation on CentOS 8 will be using dnf package manager, sudo dnf install nginx, as shown below :

[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
Installing:
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
warning: /var/cache/dnf/AppStream-a520ed22b0a8a736/packages/nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream 1.6 MB/s | 1.6 kB 00:00
Importing GPG key 0x8483C65D:
Userid : "CentOS (CentOS Official Signing Key) security@centos.org"
Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 1/8
Installing : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 1/8
Installing : nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 2/8
Running scriptlet: nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 2/8
Installing : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 3/8
Running scriptlet: nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 3/8
Installing : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 4/8
Running scriptlet: nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 4/8
Installing : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 5/8
Running scriptlet: nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 5/8
Installing : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 6/8
Installing : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 7/8
Running scriptlet: nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 7/8
Installing : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 8/8
Running scriptlet: nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 8/8
Verifying : nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 1/8
Verifying : nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 2/8
Verifying : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 3/8
Verifying : nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 4/8
Verifying : nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 5/8
Verifying : nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 6/8
Verifying : nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 7/8
Verifying : nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 8/8
Installed products updated.
Installed:
nginx-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-all-modules-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch
nginx-mod-http-image-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-http-perl-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-http-xslt-filter-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-mail-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
nginx-mod-stream-1:1.14.1-9.module_el8.0.0+184+e34fea82.x86_64
Complete!
install nginx on centos 8
Install Nginx on CentOS

After the installation is completed done, then we enable and start NginX services, by submitting command line : sudo systemctl [enable | start | status] nginx

[ramans@localhsost ~]$ sudo systemctl enable nginx
[sudo] password for ramans:
[ramans@localhsost ~]$ sudo systemctl start nginx
[ramans@localhsost ~]$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-11-06 05:25:06 PST; 10min ago
Main PID: 1575 (nginx)
Tasks: 5 (limit: 23800)
Memory: 16.1M
CGroup: /system.slice/nginx.service
├─1575 nginx: master process /usr/sbin/nginx
├─1578 nginx: worker process
├─1580 nginx: worker process
├─1582 nginx: worker process
└─1583 nginx: worker process
Nov 06 05:25:06 diginetdb01 systemd[1]: Starting The nginx HTTP and reverse proxy server…
Nov 06 05:25:06 diginetdb01 nginx[1488]: nginx: the configuration file /etc/nginx/nginx.conf syntax i>
Nov 06 05:25:06 diginetdb01 nginx[1488]: nginx: configuration file /etc/nginx/nginx.conf test is succ>
Nov 06 05:25:06 diginetdb01 systemd[1]: Started The nginx HTTP and reverse proxy server.
Enable and start Nginx Service
Enable and start Nginx Service

Adjusting The Firewall

As mentioned above, if CentOS 8 has shipped with FirewallD as the default firewall solution. Than we have to adjust the firewall settings in order to allow external connections on our Nginx web server, which r

uns on port 80 by default. We will permanently enable HTTP connections on port 80 and HTTPS connections on port 443. For this purpose, we just submit the command line below :

[ramans@localhost ~]$ sudo firewall-cmd --permanent --add-service=http
success
[ramans@localhsost ~]$ sudo firewall-cmd --permanent --add-service=https
success

To verify, if the ports are already enable just hit the command line below : sudo firewall-cmd --permanent --list-all as shown below :

[ramans@localhsost ~]$ sudo firewall-cmd --permanent --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: cockpit dhcpv6-client http https postgresql ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
sudo firewall-cmd --permanent --list-all

Testing Web Server

Now, we can test our Nginx installation, by opening http://IP_ADDRES in web browser. We should see the default Nginx welcome page, as below shown :

Nginx test page

Conclusion

So far, we have installed Nginx web server on CentOS 8 Linux operating system. By now, we can deploy an applications above it.

Share this article via :

One thought on “How To Install Nginx on CentOS 8

Leave a Reply

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