Install and configure nginx in CentOS7

Add the nginx repository

There are two ways

1. Download

$ sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Copy the code

2. Create one manually

Create a file/etc/yum. Repos. D/nginx. Repo and fill in the content

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
Copy the code

Second, the installation

$ yum install -y nginx 
Copy the code

Three, run,

1. The system is started by default

$ sudo systemctl start nginx
Copy the code

2. Start the system

Add a boot option

$ sudo systemctl enable nginx
Copy the code

3, shut down

$ sudo systemctl stop nginx
Copy the code

4. Common commands

Use the nginx command

$nginx -c /etc/nginx/nginx.confCopy the code