How To Install Nginx Server In Redhat/Centos/Fedora

In this article, we are going to learn how to install Nginx server in Linux. Nginx Server stands for Engine-X is a Web Server like Apache Web Server but gives better performance as compared to Apache Web Server. nginx is an open-source application can be used as a proxy server for email services like Internet Mail Access Protocol (IMAP), Post Office Protocol (POP), Simple Mail Transfer Protocol (SMTP) and also can be used as caching server and supports Protocols like HTTP, TCP, UDP, SSL and so on. By default, the port number of Nginx Server is 80 but you can change it as per your need and requirement. Originally the NGINX was written by Igor Sysoev.

How To Install Nginx Server In Redhat/Centos/Fedora
How To Install Nginx Server In Redhat/Centos/Fedora

Follow the below steps to Install NGINX Server In Redhat/Centos/Fedora:

First, check the IP Address of your system using ifconfig command. Here my system’s IP Address is 192.168.0.103.

[root@localhost ~]# 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 using the below command.

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

[root@localhost ~]# yum update  # Update Packages & Repositories

Before we start the installation of NGINX Server we have to install some prerequisite packages required by NGINX. First, we have to install epel-release package. EPEL stands for Extra Package for Enterprise Linux used to add some extra packages in RedHat Linux repository which is by default not comes with the operating system. So to install epel-release follow the below command.

[root@localhost ~]# 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 to Install LAMP Stack with PhpMyAdmin in Ubuntu 18.04

Now let’s go ahead and Install Nginx server package using yum command. During installation, it will ask for y or n to continue the installation. so press enter y to continue the Installation.

[root@localhost ~]# 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 installed packages you can use the rpm -qa command. refer the sample output below.

[root@localhost ~]# 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 Installation completed we have to start the nginx server service but if you have already installed and using apache web server then you have to stop the apache service. we can’t use both web servers simultaneously as both web servers are using Port 80 as their default port.

So to stop the apache web server service you can use the below command.

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

Once stopped the apache web server service you can now start the nginx server service using below command.

[root@localhost ~]# /etc/init.d/nginx start   # Start the nginx Server Service
Starting nginx:                                            [  OK  ]

As you can see above currently my nginx server service is started. Let’s try to start the apache server service, let’s see what would be the output.

As you can see below I am getting below error message that Port 80 is already in use.

[root@localhost ~]# /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.

[root@localhost ~]# chkconfig --level 35 nginx on  # Start the nginx server service at startup

You can confirm the startup enabled status using the below command.

[root@localhost ~]# chkconfig --list nginx
nginx           0:off   1:off   2:off   3:on      4:off   5:on      6:off

You can confirm. nginx currently Listening to which port by using netstat command. For that first check the status of the nginx server service using the below command. Here you will get the Process ID of nginx.

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

Then you can check the Nginx server Listen port by using a service name or by Process ID (PID) number.

Check by using Service Name : 

[root@localhost ~]# 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 by using Process ID (PID) Number :

     
[root@localhost ~]# 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 default page of Nginx server by using http://localhost OR http://YOUR_IP_ADDRESS

Snap :

How To Install Nginx Server In Redhat/Centos/Fedora
Nginx Server Default Home Page

Also Read – How to Install 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 enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.

Share this:
WhatsApp Channel Join Now
Telegram Channel Join Now
Instagram Channel Join Now

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.