How to install Nginx Server in Redhat / Centos / Fedora

This article tells you how to install the Nginx server on Linux. Nginx Server stands for Engine-X is a web server like the Apache web server, but it performs better than the Apache web server. nginx is an open source application that can be used as a proxy server for email services such as Internet mail access log (IMAP), Post protocol (POP), Simple Mail Transfer Protocol (SMTP) and can also be used as a caching server and supports protocols such as HTTP, TCP, UDP, SSL and so on. By default, the Nginx Server port number is 80, but you can change it as needed. The NGINX was originally written by Igor Sysoev,

Centos / Fedora” src=”data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7″ data-src=”https://www.itsmarttricks.com/wp-content/uploads/2019/10/How-To-Install-Nginx-Server-In-Redhat-Centos-Fedora.png” alt=”How to install Nginx Server in Redhat / Centos / Fedora” width=”781″ height=”436″ data-srcset=”https://www.itsmarttricks.com/wp-content/uploads/2019/10/How-To-Install-Nginx-Server-In-Redhat-Centos-Fedora.png 781w, https://www.itsmarttricks.com/wp-content/uploads/2019/10/How-To-Install-Nginx-Server-In-Redhat-Centos-Fedora-768×429.png 768w” data-sizes=”(max-width: 781px) 100vw, 781px”>

How to install Nginx Server in Redhat / Centos / Fedora

Follow these steps to install NGINX Server in Redhat / Centos / Fedora:

First check the IP address of your system with ifconfig Command. Here is the IP address of my system 192.168.0.103,

[[email protected] ~]# ifconfig eth0   # Checking the IP Address
eth0      Link encap:Ethernet  HWaddr 00:0C:29:41:6A:AE  
          inet addr:192.168.0.103  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe41:6aae/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:63406 errors:0 dropped:0 overruns:0 frame:0
          TX packets:35998 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:87195781 (83.1 MiB)  TX bytes:2781470 (2.6 MiB)

Update your packages and repositories with the following command.

Note: The update process will take some time and this step is optional.

[[email protected] ~]# yum update  # Update Packages & Repositories

Before we start installing NGINX Server, we need to install some prerequisite packages required for NGINX. First we have to install the Epel release package. EPEL stands for Extra Package for Enterprise Linux and is used to include some additional packages in the RedHat Linux repository, which is not delivered with the operating system by default. Follow the command below to install epel-release.

[[email protected] ~]# yum -y install epel-release  # Install epel-release Package
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:6-8 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                             Arch                          Version                     Repository                     Size
===================================================================================================================================
Installing:
 epel-release                        noarch                        6-8                         extras                         14 k

Transaction Summary
===================================================================================================================================
Install       1 Package(s)

Total download size: 14 k
Installed size: 22 k
Downloading Packages:
epel-release-6-8.noarch.rpm                                                                                 |  14 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : epel-release-6-8.noarch                                                                                         1/1 
  Verifying  : epel-release-6-8.noarch                                                                                         1/1 

Installed:
  epel-release.noarch 0:6-8                                                                                                        

Complete!

Also read – How do I install LAMP Stack with PhpMyAdmin in Ubuntu 18.04

Now let’s go ahead and install the Nginx server package with the yum command. You will be asked during the installation y or n to continue the installation. So press Enter y to continue the installation.

[[email protected] ~]# yum install nginx   # Install nginx server
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * epel: ftp.jaist.ac.jp
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Setting up Install Process
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
--> Running transaction check
---> Package nginx.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: nginx-filesystem = 1.10.2-1.el6 for package: nginx-1.10.2-1.el6.x86_64
--> Processing Dependency: nginx-all-modules = 1.10.2-1.el6 for package: nginx-1.10.2-1.el6.x86_64
--> Processing Dependency: nginx-filesystem for package: nginx-1.10.2-1.el6.x86_64
--> Running transaction check
---> Package nginx-all-modules.noarch 0:1.10.2-1.el6 will be installed
--> Processing Dependency: nginx-mod-stream = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-mail = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-perl = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-geoip = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
---> Package nginx-filesystem.noarch 0:1.10.2-1.el6 will be installed
--> Running transaction check
---> Package nginx-mod-http-geoip.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: GeoIP for package: nginx-mod-http-geoip-1.10.2-1.el6.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: nginx-mod-http-geoip-1.10.2-1.el6.x86_64
---> Package nginx-mod-http-image-filter.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: gd for package: nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
--> Processing Dependency: libgd.so.2()(64bit) for package: nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
---> Package nginx-mod-http-perl.x86_64 0:1.10.2-1.el6 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 0:1.10.2-1.el6 will be installed
---> Package nginx-mod-mail.x86_64 0:1.10.2-1.el6 will be installed
---> Package nginx-mod-stream.x86_64 0:1.10.2-1.el6 will be installed
--> Running transaction check
---> Package GeoIP.x86_64 0:1.6.5-1.el6 will be installed
--> Processing Dependency: geoipupdate for package: GeoIP-1.6.5-1.el6.x86_64
--> Processing Dependency: GeoIP-data for package: GeoIP-1.6.5-1.el6.x86_64
---> Package gd.x86_64 0:2.0.35-11.el6 will be installed
--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-11.el6.x86_64
--> Running transaction check
---> Package GeoIP-GeoLite-data.noarch 0:2017.01-1.el6 will be installed
---> Package geoipupdate.x86_64 0:2.2.1-2.el6 will be installed
---> Package libXpm.x86_64 0:3.5.10-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================
 Package                                      Arch                    Version                          Repository             Size
===================================================================================================================================
Installing:
 nginx                                        x86_64                  1.10.2-1.el6                     epel                  462 k
Installing for dependencies:
 GeoIP                                        x86_64                  1.6.5-1.el6                      epel                  113 k
 GeoIP-GeoLite-data                           noarch                  2017.01-1.el6                    epel                  468 k
 gd                                           x86_64                  2.0.35-11.el6                    base                  142 k
 geoipupdate                                  x86_64                  2.2.1-2.el6                      epel                   28 k
 libXpm                                       x86_64                  3.5.10-2.el6                     base                   51 k
 nginx-all-modules                            noarch                  1.10.2-1.el6                     epel                  7.7 k
 nginx-filesystem                             noarch                  1.10.2-1.el6                     epel                  8.5 k
 nginx-mod-http-geoip                         x86_64                  1.10.2-1.el6                     epel                   14 k
 nginx-mod-http-image-filter                  x86_64                  1.10.2-1.el6                     epel                   16 k
 nginx-mod-http-perl                          x86_64                  1.10.2-1.el6                     epel                   26 k
 nginx-mod-http-xslt-filter                   x86_64                  1.10.2-1.el6                     epel                   16 k
 nginx-mod-mail                               x86_64                  1.10.2-1.el6                     epel                   43 k
 nginx-mod-stream                             x86_64                  1.10.2-1.el6                     epel                   36 k

Transaction Summary
===================================================================================================================================
Install      14 Package(s)

Total size: 1.4 M
Installed size: 3.5 M
Is this ok [y/N]: y   ---> Enter y to continue the Installation

To confirm the installed packages, you can use the rpm -qa Command. See the following sample output.

[[email protected] ~]# rpm -qa | grep nginx   # Confirm the Installed Packages of nginx server
nginx-mod-mail-1.10.2-1.el6.x86_64
nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
nginx-mod-http-geoip-1.10.2-1.el6.x86_64
nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
nginx-mod-stream-1.10.2-1.el6.x86_64
nginx-1.10.2-1.el6.x86_64
nginx-filesystem-1.10.2-1.el6.noarch
nginx-mod-http-perl-1.10.2-1.el6.x86_64
nginx-all-modules-1.10.2-1.el6.noarch

Once the installation is complete, we need to start the Nginx server service. If you have already installed and used the Apache web server, you must stop the Apache service. We cannot use both web servers at the same time because both web servers use port 80 as the default port.

To stop the Apache web server service, you can use the following command.

[[email protected] ~]# /etc/init.d/httpd stop   # Stop the Apache Web Server Service
Stopping httpd:                                            [  OK  ]

After stopping the Apache web server service, you can now start the Nginx server service with the following command.

[[email protected] ~]# /etc/init.d/nginx start   # Start the nginx Server Service
Starting nginx:                                            [  OK  ]

As you can see above, my Nginx server service is currently started. Let’s try to start the Apache server service and let’s see what the output would look like.

As you can see below, I get the following error message that port 80 is already occupied.

[[email protected] ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
                                                           [FAILED]                                                                                                                

Start the Nginx service at startup.

[[email protected] ~]# chkconfig --level 35 nginx on  # Start the nginx server service at startup

You can confirm the start status with the following command.

[[email protected] ~]# chkconfig --list nginx
nginx           0:off   1:off   2:off   3:on      4:off   5:on      6:off

You can confirm. nginx is currently listening on which port with the command netstat. To do this, first check the status of the Nginx server service with the following command. Here you can get the process ID from nginx.

[[email protected] ~]# /etc/init.d/nginx status   # Check the Status of nginx server
nginx (pid  21312) is running...

You can then check the list port of the Nginx server using a service name or a process ID (PID).

Using the service name, check:

[[email protected] ~]# netstat -tulpn | grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      21312/nginx         
tcp        0      0 :::80                       :::*                        LISTEN      21312/nginx 

Check using the PID number (Process ID):

     
[[email protected] ~]# netstat -tulpn | grep 21312
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      21312/nginx         
tcp        0      0 :::80                       :::*                        LISTEN      21312/nginx         

Now you can check the standard page of the Nginx server http: // localhost OR http: // YOUR_IP_ADDRESS

Fang:

How to install Nginx Server in Redhat / Centos / Fedora

Standard Nginx Server homepage

READ ALSO – How To Install The Latest Webmin Control Panel In Ubuntu 18.04

That’s all. In this article we have explained how to install nginx Server in Redhat / Centos / Fedora. I hope you like this article. If you like this article, just share it. If you have any questions about this article, please comment.

Sidebar