Nginx start, stop, restart, upgrade operation command collection

  

Maybe you don't know what Nginx is, Nginx is a WEB server, like IIS, now many portals are using Nginx as a WEB server, Nginx on Linux system Running down is very good, stronger than other WEB server, you can also do load balancing, very good. The following summarizes the basic operations of Nginx. Start operation Command: nginx -c /usr/nginx/conf/nginx.conf The -c parameter specifies the path to the nginx configuration file to be loaded.

Stop operation Stop operation is performed by sending a signal to the nginx process (what is the signal, please refer to the linux article) Step 1: Query the main process number of nginx ps -ef |  Grep nginx finds the master process in the process list, its number is the main process number. Step 2: Send a signal Stop Nginx calmly: kill -QUIT Main process number Quickly stop Nginx: kill -TERM Main process number Force stop Nginx: pkill -9 nginx

In addition, if pid file is configured in nginx.conf The storage path is the Nginx main process number stored in the file. If not specified, it is placed in the logs directory of nginx. With the pid file, we don't need to query the main process number of Nginx first, but send a signal directly to Nginx. The command is as follows: kill - signal type '/usr/nginx/logs/nginx.pid'

smoothing Restart If you change the configuration, you need to restart Nginx. Do you want to close Nginx and then open it? No, you can send a signal to Nginx and smooth restart. Smooth restart command: kill -HUP live in the title or process number file path

Note that after modifying the configuration file, it is best to check whether the modified configuration file is correct, so as to avoid Nginx error after restarting. run. To determine if the Nginx configuration is correct, the command is as follows: nginx -t -c /usr/nginx/conf/nginx.conf

Smooth Upgrade If the server is running Nginx to upgrade, add or remove modules, we need to stop The server is removed and modified accordingly, so that the server will stop serving for a period of time. Nginx can perform various upgrade actions without stopping the server without affecting the server operation. Step 1: If you upgrade the Nginx program, first replace the old program file with the new program. If you compile and install the new program, compile it directly into the Nginx installation directory. Step 2: Execute the command kill -USR2 The main process number or process file name of the old program At this point, the old Nginx main process will rename its own process file to .oldbin and then execute the new version of Nginx. The old and new Nginx will run in conjunction with the city to process the request. At this time, you should gradually stop the old version of Nginx, enter the command: kill -WINCH The old version of the main process number Slowly the old work process will exit with the completion of the task, the new version of the Nginx work process will gradually replace the old version of the work process.

At this point, we can decide to use the new version or revert to the old version. Start the new/old worker process without overloading. kill -HUP Old/new version of the main process number. Close the old/new process. kill -QUIT Old/new main process number. If the error is reported at this time, the prompt and the process are not finished. Use the following command. First close the old /new worker process, then close the main process number: kill -TERM old /new work process number

This way, if you want to restore to the old version, only the above steps are all new Moderator process number, if you want to use the new version, the old master process number will be operated in the above steps.

The above is some basic operations of Nginx. I hope that Nginx will have a better way to handle these operations later. It is better to use Nginx commands instead of sending system signals to the Nginx process.

Copyright © Windows knowledge All Rights Reserved