nginx start, stop, shutdown

Time:2022-11-25

Use the centos system built by 3A server to install nginx
Tutorials are in my previous blog
1, nginx specifies the configuration file

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
1
The -c parameter specifies the path of the nginx configuration file to be loaded
1. Stop Nginx calmly:
kill -QUIT main process number
2, Stop Nginx quickly:
kill -TERM main process number

3. Force stop Nginx:
kill -9 main process number

2. Use signals to manage the master and worker processes of nginx
Immediately stop the service:
nginx -s stop or
kill -SIGTERM $(cat /data/services/nginx/logs/nginx.pid)

Stop the service gracefully:
nginx -s quit or
kill -QUIT $(cat /data/services/nginx/logs/nginx.pid)

Reload configuration file (master does not exit, reloads worker process):
nginx -s reload
kill -SIGHUP $(cat /data/services/nginx/logs/nginx.pid)

Restart logging to the log file:
nginx -s reopen or
kill -USR1 $(cat /data/services/nginx/logs/nginx.pid)

Hot upgrade nginx service (mainly binary nginx files):
kill -USR2 old_master_process #transfer new requests to the new master process
kill -WINCH old_master_process #Elegantly close all work processes

nginx reload process
(1) Send a HUP signal to the master process (reload command)
(2) The master process checks whether the syntax of the configuration file is correct
(3) The master process opens a new listening port
(4) The master process starts a new worker subprocess with the new configuration
(5) The master process sends a QUIT signal to the old worker child process
(6) The old worker process closes the listening handle and ends the process after processing the current connection

nginx hot upgrade process
(1) Replace the old nginx file with the new nginx file
(2) Send USR2 signal to the master process
(3) The master process modifies the pid file name and adds the suffix .oldbin
(4) The master process starts a new master process with a new nginx file
(5) Send a WINCH signal to the old master process and close the old worker
(6) Rollback: send HUP to the old master, send QUIT to the new master
3, When using systemctl to start the service, when reporting start-pre, you can consider whether /var/tmp exists
nginx.service failed to run ‘start-pre’
nginx start, stop, shutdown
Startup script:

cat >> nginx.service << EOF
[Unit]
Description=nginx web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking
User=root
Group=root
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
PrivateTmp=true

Recommended Today

I have been in contact with Git for so long, let’s talk about my understanding of Git and related things

1. The birth of Git and related history 1.1 Definition of Git ​ Git fordistributedThe version control system is currently the most advancedversion controlsystem. think: What does version control mean? Wikipedia: Version control (English: Version control) is a standard practice for maintaining engineering blueprints, which can track the process of engineering blueprints from birth to […]