How To Install Nginx on CentOS 7

0
424

Nginx Installation

Nginx (pronounced “engine x”) is a web server created by Igor Sysoev. Which can be used as a reverse proxy server for TCP, UDP, HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and HTTP cache.

first, add the EPEL repository by using the following command

[root@localhost ~]# yum install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

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

Transaction Summary
========================================================================================================================================================================
Install  1 Package

Total download size: 14 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-6.noarch.rpm                                                                                                                      |  14 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-6.noarch                                                                                                                              1/1
  Verifying  : epel-release-7-6.noarch                                                                                                                              1/1

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

Complete!
[root@localhost ~]#

We can install Nginx very easily by using yum command as follows

yum install nginx
 [root@localhost ~]# yum install nginx
Loaded plugins: fastestmirror, langpacks
 (1/3): epel/x86_64/group_gz                                                                                                                      | 170 kB  00:00:01
 (2/3): epel/x86_64/updateinfo                                                                                                                    | 630 kB  00:00:03
(3/3): epel/x86_64/primary_db                                                                                                                    | 4.2 MB  00:00:36
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * epel: epel.mirror.net.in
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.10.1-1.el7 will be installed
--> Processing Dependency: nginx-filesystem = 1:1.10.1-1.el7 for package: 1:nginx-1.10.1-1.el7.x86_64
--> Processing Dependency: nginx-all-modules = 1:1.10.1-1.el7 for package: 1:nginx-1.10.1-1.el7.x86_64
--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.10.1-1.el7.x86_64
--> Running transaction check
---> Package nginx-all-modules.noarch 1:1.10.1-1.el7 will be installed
--> Processing Dependency: nginx-mod-stream = 1:1.10.1-1.el7 for package: 1:nginx-all-modules-1.10.1-1.el7.noarch
--> Processing Dependency: nginx-mod-mail = 1:1.10.1-1.el7 for package: 1:nginx-all-modules-1.10.1-1.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.10.1-1.el7 for package: 1:nginx-all-modules-1.10.1-1.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = 1:1.10.1-1.el7 for package: 1:nginx-all-modules-1.10.1-1.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1:1.10.1-1.el7 for package: 1:nginx-all-modules-1.10.1-1.el7.noarch
--> Processing Dependency: nginx-mod-http-geoip = 1:1.10.1-1.el7 for package: 1:nginx-all-modules-1.10.1-1.el7.noarch
---> Package nginx-filesystem.noarch 1:1.10.1-1.el7 will be installed
--> Running transaction check
---> Package nginx-mod-http-geoip.x86_64 1:1.10.1-1.el7 will be installed
--> Processing Dependency: GeoIP for package: 1:nginx-mod-http-geoip-1.10.1-1.el7.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: 1:nginx-mod-http-geoip-1.10.1-1.el7.x86_64
---> Package nginx-mod-http-image-filter.x86_64 1:1.10.1-1.el7 will be installed
---> Package nginx-mod-http-perl.x86_64 1:1.10.1-1.el7 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.10.1-1.el7 will be installed
---> Package nginx-mod-mail.x86_64 1:1.10.1-1.el7 will be installed
---> Package nginx-mod-stream.x86_64 1:1.10.1-1.el7 will be installed
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-9.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                               Arch                             Version                                    Repository                      Size
========================================================================================================================================================================
Installing:
 nginx                                                 x86_64                           1:1.10.1-1.el7                             epel                           504 k
Installing for dependencies:
 GeoIP                                                 x86_64                           1.5.0-9.el7                                base                           709 k
 nginx-all-modules                                     noarch                           1:1.10.1-1.el7                             epel                            16 k
 nginx-filesystem                                      noarch                           1:1.10.1-1.el7                             epel                            17 k
 nginx-mod-http-geoip                                  x86_64                           1:1.10.1-1.el7                             epel                            23 k
 nginx-mod-http-image-filter                           x86_64                           1:1.10.1-1.el7                             epel                            26 k
 nginx-mod-http-perl                                   x86_64                           1:1.10.1-1.el7                             epel                            35 k
 nginx-mod-http-xslt-filter                            x86_64                           1:1.10.1-1.el7                             epel                            25 k
 nginx-mod-mail                                        x86_64                           1:1.10.1-1.el7                             epel                            53 k
 nginx-mod-stream                                      x86_64                           1:1.10.1-1.el7                             epel                            46 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package (+9 Dependent packages)

Total download size: 1.4 M
Installed size: 3.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/10): GeoIP-1.5.0-9.el7.x86_64.rpm                                                                                                             | 709 kB  00:00:01
warning: /var/cache/yum/x86_64/7/epel/packages/nginx-filesystem-1.10.1-1.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYs | 747 kB  00:00:01 ETA
Public key for nginx-filesystem-1.10.1-1.el7.noarch.rpm is not installed
(2/10): nginx-filesystem-1.10.1-1.el7.noarch.rpm                                                                                                 |  17 kB  00:00:01
(3/10): nginx-all-modules-1.10.1-1.el7.noarch.rpm                                                                                                |  16 kB  00:00:01
(4/10): nginx-mod-http-perl-1.10.1-1.el7.x86_64.rpm                                                                                              |  35 kB  00:00:00
(5/10): nginx-mod-http-xslt-filter-1.10.1-1.el7.x86_64.rpm                                                                                       |  25 kB  00:00:00
(6/10): nginx-mod-mail-1.10.1-1.el7.x86_64.rpm                                                                                                   |  53 kB  00:00:00
(7/10): nginx-mod-stream-1.10.1-1.el7.x86_64.rpm                                                                                                 |  46 kB  00:00:00
(8/10): nginx-mod-http-geoip-1.10.1-1.el7.x86_64.rpm                                                                                             |  23 kB  00:00:04
(9/10): nginx-mod-http-image-filter-1.10.1-1.el7.x86_64.rpm                                                                                      |  26 kB  00:00:06
(10/10): nginx-1.10.1-1.el7.x86_64.rpm                                                                                                           | 504 kB  00:00:08
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   164 kB/s | 1.4 MB  00:00:08
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-6.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:nginx-filesystem-1.10.1-1.el7.noarch                                                                                                              1/10
  Installing : GeoIP-1.5.0-9.el7.x86_64                                                                                                                            2/10
  Installing : 1:nginx-mod-http-geoip-1.10.1-1.el7.x86_64                                                                                                          3/10
  Installing : 1:nginx-mod-stream-1.10.1-1.el7.x86_64                                                                                                              4/10
  Installing : 1:nginx-mod-http-image-filter-1.10.1-1.el7.x86_64                                                                                                   5/10
  Installing : 1:nginx-mod-http-perl-1.10.1-1.el7.x86_64                                                                                                           6/10
  Installing : 1:nginx-mod-http-xslt-filter-1.10.1-1.el7.x86_64                                                                                                    7/10
  Installing : 1:nginx-1.10.1-1.el7.x86_64                                                                                                                         8/10
  Installing : 1:nginx-mod-mail-1.10.1-1.el7.x86_64                                                                                                                9/10
  Installing : 1:nginx-all-modules-1.10.1-1.el7.noarch                                                                                                            10/10
  Verifying  : 1:nginx-mod-mail-1.10.1-1.el7.x86_64                                                                                                                1/10
  Verifying  : 1:nginx-1.10.1-1.el7.x86_64                                                                                                                         2/10
  Verifying  : 1:nginx-mod-http-geoip-1.10.1-1.el7.x86_64                                                                                                          3/10
  Verifying  : GeoIP-1.5.0-9.el7.x86_64                                                                                                                            4/10
  Verifying  : 1:nginx-filesystem-1.10.1-1.el7.noarch                                                                                                              5/10
  Verifying  : 1:nginx-mod-stream-1.10.1-1.el7.x86_64                                                                                                              6/10
  Verifying  : 1:nginx-mod-http-image-filter-1.10.1-1.el7.x86_64                                                                                                   7/10
  Verifying  : 1:nginx-mod-http-perl-1.10.1-1.el7.x86_64                                                                                                           8/10
  Verifying  : 1:nginx-mod-http-xslt-filter-1.10.1-1.el7.x86_64                                                                                                    9/10
  Verifying  : 1:nginx-all-modules-1.10.1-1.el7.noarch                                                                                                            10/10

Installed:
  nginx.x86_64 1:1.10.1-1.el7

Dependency Installed:
  GeoIP.x86_64 0:1.5.0-9.el7                               nginx-all-modules.noarch 1:1.10.1-1.el7                   nginx-filesystem.noarch 1:1.10.1-1.el7
  nginx-mod-http-geoip.x86_64 1:1.10.1-1.el7               nginx-mod-http-image-filter.x86_64 1:1.10.1-1.el7         nginx-mod-http-perl.x86_64 1:1.10.1-1.el7
  nginx-mod-http-xslt-filter.x86_64 1:1.10.1-1.el7         nginx-mod-mail.x86_64 1:1.10.1-1.el7                      nginx-mod-stream.x86_64 1:1.10.1-1.el7

Complete!
[root@localhost ~]# 

Test Nginx by using the Url http://localhost or http://ip-address in your Browser.

nginx homepage

The configuration of Nginx file is available at /etc/nginx/nginx.conf for further configuration.