Install nginx on centOS7

Reference site

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
# firewall-cmd --add-service=http --permanent
# firewall-cmd --reload
# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  services: dhcpv6-client http ssh
  masquerade: no
  rich rules:

To install nginx, you need to add a repository for nginx. Check the current repository file.

$ ls -s /etc/yum.repos.d/
total 48
 4 CentOS-Base.repo        4 CentOS-Media.repo           4 epel.repo
 4 CentOS-CR.repo          4 CentOS-Sources.repo         4 epel-testing.repo
 4 CentOS-Debuginfo.repo  12 CentOS-Vault.repo
 4 CentOS-fasttrack.repo   4 CentOS-x86_64-kernel.repo

Add the repository file for nginx to the above directory.

Add repository file for nginx

# vi /etc/yum.repos.d/nginx.repo

#Describe the following with reference to the official website
name=nginx repo


Make additional confirmations.

$ yum search nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
nginx                                                    | 2.9 kB     00:00
nginx/x86_64/primary_db                                    | 186 kB   00:01
============================== N/S matched: nginx ==============================
collectd-nginx.x86_64 : Nginx plugin for collectd
munin-nginx.noarch : NGINX support for Munin resource monitoring
nginx-all-modules.noarch : A meta package that installs all available Nginx
                         : modules
nginx-debug.x86_64 : debug version of nginx
nginx-debuginfo.x86_64 : Debug information for package nginx
nginx-filesystem.noarch : The basic directory layout for the Nginx server
nginx-mod-http-image-filter.x86_64 : Nginx HTTP image filter module
nginx-mod-http-perl.x86_64 : Nginx HTTP perl module
nginx-mod-http-xslt-filter.x86_64 : Nginx XSLT module
nginx-mod-mail.x86_64 : Nginx mail modules
nginx-mod-stream.x86_64 : Nginx stream modules
nginx-module-geoip.x86_64 : nginx GeoIP dynamic modules
nginx-module-geoip-debuginfo.x86_64 : Debug information for package
                                    : nginx-module-geoip
nginx-module-image-filter.x86_64 : nginx image filter dynamic module
nginx-module-image-filter-debuginfo.x86_64 : Debug information for package
                                           : nginx-module-image-filter
nginx-module-njs.x86_64 : nginx njs dynamic modules
nginx-module-njs-debuginfo.x86_64 : Debug information for package
                                  : nginx-module-njs
nginx-module-perl.x86_64 : nginx Perl dynamic module
nginx-module-perl-debuginfo.x86_64 : Debug information for package
                                   : nginx-module-perl
nginx-module-xslt.x86_64 : nginx xslt dynamic module
nginx-module-xslt-debuginfo.x86_64 : Debug information for package
                                   : nginx-module-xslt
nginx-nr-agent.noarch : New Relic agent for NGINX and NGINX Plus
owncloud-nginx.noarch : Nginx integration for ownCloud
pagure-web-nginx.noarch : Nginx configuration for Pagure
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx
                      : Webserver
python2-certbot-nginx.noarch : The nginx plugin for certbot
sympa-nginx.x86_64 : Sympa with nginx
nginx.x86_64 : High performance web server
unit.x86_64 : NGINX Unit
unit-devel.x86_64 : NGINX Unit (development tools)

  Name and summary matches only, use "search all" for everything.

By the way, the packages required for nginx installation are nginx.x86_64 : High performance web server is.

nginx installation

First, check the information of the nginx package.

$ yum info nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * extras:
 * updates:
Installed Packages
Name        : nginx
Arch        : x86_64
Epoch       : 1
Version     : 1.16.1
Release     : 3.el7
Size        : 1.6 M
Repo        : installed
From repo   : epel
Summary     : A high performance web server and reverse proxy server
URL         :
License     : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, SMTP,
            : POP3 and IMAP protocols, with a strong focus on high concurrency,
            : performance and low memory usage.

Available Packages
Name        : nginx
Arch        : x86_64
Epoch       : 1
Version     : 1.19.5
Release     : 1.el7.ngx
Size        : 788 k
Repo        : nginx/x86_64
Summary     : High performance web server
URL         :
License     : 2-clause BSD-like license
Description : nginx [engine x] is an HTTP and reverse proxy server, as well as
            : a mail proxy server.

Now install the nginx package.

#-You can omit the confirmation response during installation by adding the y option.(I did not know)
# yum -y install nginx

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 8.7 kB     00:00
 * base:
 * epel:
 * extras:
 * updates:
base                                                     | 3.6 kB     00:00
extras                                                   | 2.9 kB     00:00
nginx                                                    | 2.9 kB     00:00
updates                                                  | 2.9 kB     00:00
nginx/x86_64/primary_db                                    | 186 kB   00:01
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.16.1-3.el7 will be updated
---> Package nginx.x86_64 1:1.19.5-1.el7.ngx will be an update
--> Finished Dependency Resolution

Dependencies Resolved

 Package       Arch           Version                       Repository     Size
 nginx         x86_64         1:1.19.5-1.el7.ngx            nginx         788 k

Transaction Summary
Upgrade  1 Package

Total download size: 788 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
nginx-1.19.5-1.el7.ngx.x86_64.rpm                          | 788 kB   00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:nginx-1.19.5-1.el7.ngx.x86_64                              1/2
  Cleanup    : 1:nginx-1.16.1-3.el7.x86_64                                  2/2
  Verifying  : 1:nginx-1.19.5-1.el7.ngx.x86_64                              1/2
  Verifying  : 1:nginx-1.16.1-3.el7.x86_64                                  2/2

  nginx.x86_64 1:1.19.5-1.el7.ngx

Check the installed nginx package

$ yum list installed | grep nginx
nginx.x86_64                       1:1.19.5-1.el7.ngx             @nginx

It was installed.

Start nginx

$ systemctl start nginx
#Check if it is running
$ systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2020-12-13 09:36:54 JST; 17s ago
  Process: 30579 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 30580 (nginx)
   CGroup: /system.slice/nginx.service
           tq30580 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx....
           mq30581 nginx: worker process

Dec 13 09:36:54 f5les1se systemd[1]: Starting nginx - high performance web .....
Dec 13 09:36:54 f5les1se systemd[1]: Can't open PID file /var/run/
Dec 13 09:36:54 f5les1se systemd[1]: Started nginx - high performance web s...r.
Hint: Some lines were ellipsized, use -l to show in full.

Since it is Active: active (running), it is working normally. There seems to be another way to check the running process with the ps command.

$ ps -aux | grep nginx
root     30580  0.0  0.0  46492   972 ?        Ss   09:36   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx    30581  0.0  0.1  46884  1600 ?        S    09:36   0:00 nginx: worker process
admin    30602  0.0  0.0 112812   972 pts/0    S+   09:39   0:00 grep --color=auto nginx

nginx autostart settings

Set nginx to start automatically when the servo is restarted. Again, use the systemctl command.

#enable on centOS means autostart
$ systemctl enable nginx

Make sure that it is set to start automatically.

$ systemctl is-enabled nginx

Since it is enabled, the setting is completed.

Confirmation on the web page

With the above procedure, you should be able to display the "web page" provided by default in the nginx package. Find the IP address of the server where you installed nginx from your web browser. Example:


If the above screen is displayed, the setting is completed normally.

Recommended Posts

Install nginx on centOS7
Install Golang on CentOS 8
Install Neo4j 4.1.3 on centOS
Install Vertica 10.0 on CentOS 6.10
Install PostgreSQL 12 on Centos8
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Command to install nginx / PHP7 / php-fpm on CentOS7
Install OpenFOAM v2006 on CentOS
Install Jenkins on Docker's CentOS
Install Apache on CentOS on VirtualBox
Install Ruby 2.7 on CentOS 7 (SCL)
Try DPDK20 SDK on CentOS7 ①Install
Install Ruby 2.5 on CentOS 7 using SCL
Install Java Open JDK 8 on CentOS 7
How to install MariaDB 10.4 on CentOS 8
Install apache 2.4.46 from source on CentOS7
Steps to install MySQL 8 on CentOS 8
Steps to install devtoolset-6 on CentOS 7
Install Java 9 on windows 10 and CentOS 7
Install MariaDB (CentOS 8)
Note: Install nginx from official repositories with dnf on CentOS 8
[CentOS] Install apache-loggen
OpenVPN on CentOS 8
Install samba4 from source code on CentOS8
Install the webmail client Rainloop on CentOS 8
How to install beta php8.0 on CentOS8
Install CentOS 7 on Raspberry pi 4 Model B
Installing and configuring ClipBucket and Nginx on CentOS 7
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Install gradle on mac
Install Corretto 8 on Windows
Maven on CentOS 7 tutorial
Install OpenJDK on macOS
Install Java on Mac
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install pyqt5 on ubuntu
Try OpenLiteSpeed on CentOS8
[CentOS7] Install aws cli
Install Docker on Manjaro
Install Ruby on Ubuntu 20.04
Use mod_auth_cas on CentOS 8
Install lombok on SpringToolSuite4
Install GitLab on CentOS 8 with no internet connection
Use bat on Centos.
Jetty v8 on CentOS7
Install Autoware on Ubuntu 18.04.5
OpenJDK installation on CentOS 7
Install openjdk11 on mac
Install Homebrew on Ubuntu 20.04
Install CMS Made Simple v2.2.2 on LAMP on CentOS 7.3
Install OpenJDK 8 on mac
Install BookStack Documentation Wiki on Elastic Compute Service on CentOS 7
Install the latest hardware drivers from ELRepo on CentOS