Nginx start stop restart upgrade operation command collection

  • 2020-05-06 12:14:02
  • OfStack

The following is a summary of the basic operations of Nginx.
startup operation
Command:
nginx -c /usr/nginx/conf/nginx.conf
The -c parameter specifies the nginx configuration file path to load.

stops operating
The
stop operation is performed by sending a signal to the nginx process (see the linux article for what is a signal) Step 1: query nginx main process number
ps -ef | grep nginx
Find the master process in the process list, and its number is the main process number.
Step 2: send the signal
leisurely stop Nginx:
Es30en-QUIT main process number
quick stop Nginx:
kill-TERM main process number
forces Nginx to stop:
pkill -9 nginx

In addition, if the pid file storage path is configured in nginx.conf, the file will hold the Nginx main process number, or if not specified, it will be placed in the logs directory of nginx. With the pid file, we don't have to look up the Nginx main process number first, but we can send a signal to Nginx directly. The command is
kill - signal types'/usr nginx/logs/nginx pid '

Restart
smoothly If you change the configuration, you need to restart Nginx. Do you need to close Nginx before opening it? No, you can send a signal to Nginx to smooth the restart.
Smooth restart command:
Es73en-HUP lives in the title or process number file path

Note that it is best to check that the modified configuration file is correct before you modify it, so as not to affect the stable operation of the server due to errors in Nginx after restart. Determine if the Nginx configuration is correct with the following command:
nginx -t -c /usr/nginx/conf/nginx.conf

Smooth upgrade to
If the Nginx running on the server needs to upgrade, add or remove modules, we need to stop the server and make corresponding modifications, so that the server will be out of service for a period of time, Nginx can do all kinds of upgrades without affecting the server.
Step 1:
If you upgrade the Nginx program, replace the old program file with the new program, and compile and install the new program directly into the Nginx installation directory.
Step 2: execute the command
Es94en-USR2 main process number or process file name
At this point the old Nginx main process will rename its own process file to.oldbin and then execute the new Nginx. The new and old Nginx operate in conjunction with the city to process requests.
To phase out the old Nginx, type
kill -WINCH old moderator process number
Over time, the old worker process will exit with the completion of the task, and the new Nginx worker process will gradually replace the old worker process.

At this point, we can decide whether to use the new version or revert to the old version.
Start the new/old worker process
without overloading the configuration Es113en-HUP old/new moderator process number
Gracefully close the old/new process
kill -QUIT old/new main process number
If an error is reported at this time, the old/new worker process is not finished, then the main process number:
is closed with the following command kill -TERM old/new working process number

In this way, if you want to restore to the old version, you only need the above steps to operate the new moderator process number, if you want to use the new version of the above steps to operate the old moderator process number.

Above are some of the basic operations of Nginx, and hopefully Nginx will have a better way to handle these operations in the future, preferably with Nginx commands rather than sending system signals to the Nginx process.

Related articles: