[CentOS7 install Nginx]

Install Nginx on CentOS7
1. Download the package
wget http://nginx.org/download/nginx-1.20.2.tar.gz
1
2. Install dependencies
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
1
3 .Install Nginx
#Unzip
tar -zxvf nginx-1.20.2.tar.gz

#Enter the NG directory
cd ./nginx-1.20.2

#Configuration
./configure --prefix=/usr/local/nginx

#Compile
make
make install

4. Start&Stop
#Start
/usr/local/nginx/sbin/nginx

#Reload configuration
/usr/local/nginx/sbin/nginx -s reload

#停止
/usr/local/nginx/sbin/nginx -s stop

5. Other commands
Start with the configuration file in a specific directory: nginx -c /specific directory/nginx.conf
Reload configuration: nginx -s reload After executing this command, the master process will wait for the worker process to finish processing the current request, and then according to the latest The configuration recreates a new worker process to complete the hot update of the Nginx configuration.
Immediately stop the service: nginx -s stop
Calmly stop the service: nginx -s quit After executing this command, Nginx will stop after completing the current task.
Check whether the configuration file is correct: nginx -t
Check whether the configuration file of a specific directory is correct: nginx -t -c /specific directory/nginx.conf
View version information: nginx -v

6. Set Nginx to start automatically at boot.
The first step
is to create the nginx.service file
vim /lib/systemd/system/nginx.service

The writing content is as follows

[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Note that
the start, restart, and stop commands of [Service] all require the use of absolute paths. The
relevant settings for service installation under the [Install] run level can be set to multi-user, that is, the system run level is 3.
For the location of nginx, you can use find / -name nginx looks for

The second step
is to set the automatic start-up

systemctl enable nginx

7. Start & stop
systemctl start nginx.service #(Start nginx service)
systemctl stop nginx.service #(Stop nginx service)
systemctl enable nginx.service #(Set boot self-start)
systemctl disable nginx.service #(Stop boot self-start )
systemctl status nginx.service #(view the current status of the service)
systemctl restart nginx.service #(restart the service)
systemctl list-units --type=service #(view all started services)

Refer to the link
Installation tutorial to set Nginx to start Nginx
automatically after booting

おすすめ

転載: blog.csdn.net/wr9zgo48/article/details/124285030