How to Install Nginx in Linux CentOS 7

Posted on

Introduction

Another article for showing steps for installing Nginx in Linux CentOS 7. The installation exist in a server or a machine running with an operating system of CentOS 7. In this case, the installation of Nginx has the purpose of having a web application server running. It will provide a service to handle request to a web application running on it. Another type of web application server which is available and quite popular is Apache Webserver.

Nginx Installation

So, the following is the installation step of Nginx in a machine or server running Linux CentOS 7 :

  1. [root@localhost ~]# yum -y install nginx
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    epel/x86_64/metalink                                                                             | 6.0 kB  00:00:00
     * base: xxxxxxxxx.xxxxxx.xxx.xxx
     * epel: xxxxxxxxx.xxxxxxxxxxxxxxxxxx.xxx.xxx
     * extras: xxxxxxxxx.xxxxxxxxx.xxx.xxx
     * updates: xxxxxxxxx.xxxxxxxxx.xxx.xxx
    epel                                                                                             | 4.7 kB  00:00:00
    (1/3): epel/x86_64/group_gz                                                                      |  96 kB  00:00:09
    (2/3): epel/x86_64/updateinfo                                                                    | 1.0 MB  00:00:09
    (3/3): epel/x86_64/primary_db                                                                    | 7.0 MB  00:00:17
    Resolving Dependencies
    --> Running transaction check
    ---> Package nginx.x86_64 1:1.20.1-9.el7 will be installed
    --> Processing Dependency: nginx-filesystem = 1:1.20.1-9.el7 for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: libcrypto.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_0)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: libssl.so.1.1(OPENSSL_1_1_1)(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: nginx-filesystem for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: redhat-indexhtml for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: system-logos for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: libcrypto.so.1.1()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Processing Dependency: libssl.so.1.1()(64bit) for package: 1:nginx-1.20.1-9.el7.x86_64
    --> Running transaction check
    ---> Package centos-indexhtml.noarch 0:7-9.el7.centos will be installed
    ---> Package centos-logos.noarch 0:70.0.6-3.el7.centos will be installed
    ---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed
    ---> Package nginx-filesystem.noarch 1:1.20.1-9.el7 will be installed
    ---> Package openssl11-libs.x86_64 1:1.1.1g-3.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ======================================================================================================================== Package                          Arch                   Version                             Repository            Size
    ========================================================================================================================Installing:
     nginx                            x86_64                 1:1.20.1-9.el7                      epel                 587 k
    Installing for dependencies:
     centos-indexhtml                 noarch                 7-9.el7.centos                      base                  92 k
     centos-logos                     noarch                 70.0.6-3.el7.centos                 base                  21 M
     gperftools-libs                  x86_64                 2.6.1-1.el7                         base                 272 k
     nginx-filesystem                 noarch                 1:1.20.1-9.el7                      epel                  24 k
     openssl11-libs                   x86_64                 1:1.1.1g-3.el7                      epel                 1.5 M
    
    Transaction Summary
    ========================================================================================================================Install  1 Package (+5 Dependent packages)
    
    Total download size: 24 M
    Installed size: 28 M
    Downloading packages:
    (1/6): centos-indexhtml-7-9.el7.centos.noarch.rpm                                                |  92 kB  00:00:00
    (2/6): gperftools-libs-2.6.1-1.el7.x86_64.rpm                                                    | 272 kB  00:00:00
    warning: /var/cache/yum/x86_64/7/epel/packages/nginx-1.20.1-9.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Public key for nginx-1.20.1-9.el7.x86_64.rpm is not installed
    (3/6): nginx-1.20.1-9.el7.x86_64.rpm                                                             | 587 kB  00:00:00
    (4/6): centos-logos-70.0.6-3.el7.centos.noarch.rpm                                               |  21 MB  00:00:01
    openssl11-libs-1.1.1g-3.el7.x8 FAILED
    (5/6): openssl11-libs-1.1.1g-3.el7.x86_64.rpm                                                    | 1.5 MB  00:00:00
    (6/6): nginx-filesystem-1.20.1-9.el7.noarch.rpm                                                  |  24 kB  00:00:13
    ------------------------------------------------------------------------------------------------------------------------Total                                                                                   1.7 MB/s |  24 MB  00:00:13
    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-11.noarch (@extras)
     From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : centos-logos-70.0.6-3.el7.centos.noarch                                                              1/6
      Installing : centos-indexhtml-7-9.el7.centos.noarch                                                               2/6
      Installing : 1:openssl11-libs-1.1.1g-3.el7.x86_64                                                                 3/6
      Installing : gperftools-libs-2.6.1-1.el7.x86_64                                                                   4/6
      Installing : 1:nginx-filesystem-1.20.1-9.el7.noarch                                                               5/6
      Installing : 1:nginx-1.20.1-9.el7.x86_64                                                                          6/6
      Verifying  : 1:nginx-filesystem-1.20.1-9.el7.noarch                                                               1/6
      Verifying  : 1:nginx-1.20.1-9.el7.x86_64                                                                          2/6
      Verifying  : gperftools-libs-2.6.1-1.el7.x86_64                                                                   3/6
      Verifying  : 1:openssl11-libs-1.1.1g-3.el7.x86_64                                                                 4/6
      Verifying  : centos-indexhtml-7-9.el7.centos.noarch                                                               5/6
      Verifying  : centos-logos-70.0.6-3.el7.centos.noarch                                                              6/6
    
    Installed:
      nginx.x86_64 1:1.20.1-9.el7
    
    Dependency Installed:
      centos-indexhtml.noarch 0:7-9.el7.centos                   centos-logos.noarch 0:70.0.6-3.el7.centos
      gperftools-libs.x86_64 0:2.6.1-1.el7                       nginx-filesystem.noarch 1:1.20.1-9.el7
      openssl11-libs.x86_64 1:1.1.1g-3.el7
    
    Complete!
    [root@localhost ~]#
    
  2. [root@localhost ~]# systemctl enable nginx
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.[root@djpk-sinergi ~]# systemctl start nginx
    [root@localhost ~]#
    
  3. Start the Nginx service by typing the following command :

    [root@localhost ~]# systemctl start nginx
    [root@localhost ~]#
    
  4. Last but not least, just check the status of Nginx running by typing the following command just to check whether it is currently running properly :

    [root@localhost ~]# 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 Thu 2021-11-25 15:26:48 UTC; 15min ago
      Process: 1738 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
      Process: 1733 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
      Process: 1732 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
     Main PID: 1740 (nginx)
       CGroup: /system.slice/nginx.service
               ├─1740 nginx: master process /usr/sbin/nginx
               ├─1741 nginx: worker process
               └─1742 nginx: worker process
    
    Nov 25 15:26:47 localhost systemd[1]: Starting The nginx HTTP and reverse proxy server...
    Nov 25 15:26:48 localhost nginx[1733]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    Nov 25 15:26:48 localhost nginx[1733]: nginx: configuration file /etc/nginx/nginx.conf test is successful
    Nov 25 15:26:48 localhost systemd[1]: Started The nginx HTTP and reverse proxy server.
    [root@localhost ~]#
    

Leave a Reply