Nginx starts, restarts, closes the command

  
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 nginx main process number ps -ef |  Grep nginx looks for the master process in the process list, its number is the main process number. Step 2: Send a signal to stop Nginx: kill -QUIT The main process number is quickly stopped. Nginx:kill -TERM The main process number is forcibly stopped. Nginx:pkill -9 nginx In addition, if the pid file storage path is configured in nginx.conf, the file is stored. The Nginx main process number, if not specified, 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' smooth restart if the configuration is changed 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 to enter the title or process number file path

or use


/usr/nginx/sbin/nginx -s reload

< Br>


Note, after modifying the configuration file, it is best to check whether the modified configuration file is correct, so as to avoid the Nginx error after the restart, which affects the stable operation of the server. The command to determine whether the Nginx configuration is correct is as follows: nginx -t -c /usr/nginx/conf/nginx.conf

or
/usr/nginx/sbin/nginx -t


< Br>Smooth upgrade If the server is running Nginx to upgrade, add or remove modules, we need to stop the server and modify it accordingly, so the server will stop service for a period of time, Nginx can be carried out without downtime Various upgrade actions without affecting 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 time, the old Nginx main process will rename its own process file to .oldbin and 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 will slowly exit the old work process as the task is completed, the new 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. Do not reload the configuration to start the new /old work process kill -HUP old /new version of the main process number gracefully close the old /new process kill -QUIT old /new main process number If the error is reported at this time, the prompt is still not ended, use the following command Close the old /new worker process, then close the main process number: kill -TERM old /new work process number. If you want to restore to the old version, only the above steps are to operate the new version of the main process number, if To use the new version to operate the old master process number 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. ==========================================================  Grep nginx/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confkill -quit 5900

Copyright © Windows knowledge All Rights Reserved