CentOS7.2 Method steps for installing Nginx

  • 2020-06-12 11:35:29
  • OfStack

CentOS7.2 Install the Nginx process notes. Due to the study requirement, learn 1 "nginx" during this period. Learn 1 Nginx installation today, and leave a note

See the version of CentOS

Use 1 command to view 1 version of the current system

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

Add the repository

To install Nginx on an CentOS system, you must first add a repository, like this:

vim /etc/yum.repos.d/nginx.repo

Use vim command to open/etc/yum repos. d/nginx repo, if nginx repo does not exist, would be to create a such a file, open since small i under press 1 key, enter the edit mode, and then copy and paste the following a few lines of code, complete press esc exit, and then input: wq (save and exit)

name=nginx repo

The yum command goes to install nginx

With this done, we can use the yum command to install nginx

yum install nginx

Successful installation:

Loaded plugins: fastestmirror, langpacks
nginx                          | 2.9 kB   00:00   
nginx/7/x86_64/primary_db                 | 14 kB  00:01   
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.btte.net
 * updates: mirrors.sina.cn
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.10.1-1.el7.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package    Arch      Version            Repository   Size
 nginx     x86_64     1:1.10.1-1.el7.ngx      nginx     640 k

Transaction Summary
Install 1 Package

Total download size: 640 k
Installed size: 2.1 M
Is this ok [y/d/N]: y
Downloading packages:
nginx-1.10.1-1.el7.ngx.x86_64.rpm             | 640 kB  00:27   
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : 1:nginx-1.10.1-1.el7.ngx.x86_64               1/1 

Thanks for using nginx!

Please find the official documentation for nginx here:
* http://nginx.org/en/docs/

Commercial subscriptions for nginx are available on:
* http://nginx.com/products/

 Verifying : 1:nginx-1.10.1-1.el7.ngx.x86_64               1/1 

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


Test the nginx configuration file

When you execute nginx-t, nginx will test the syntax of your configuration file and tell you whether the configuration file is written correctly. It also tells you the path of the configuration file:

nginx -t

Print as follows:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Configuration file successful!

centos7.0 + nginx implements stop, start and restart

In CentOS7, the chkconfig command operation is similar to "systemctl..." systemctl can simply realize the combination of service and chkconfig, so that one command can realize the function of two commands.

The basic operation format of the systemctl command is:

systemctl [OPTIONS...] {COMMAND}...

Taking nginx service as an example, the actions of stopping, starting and restarting are as follows:

systemctl stop  nginx.service
systemctl start  nginx.service
systemctl restart nginx.service

Check service status

systemctl status nginx.service

Get the service up and running

vim /etc/yum.repos.d/nginx.repo

Cancel service startup

vim /etc/yum.repos.d/nginx.repo

Related articles: