Simple command to restart Nginx

  
                  

When we install a new program in Nginx, we need to restart it. In fact, there is a little trick when restarting. The kill command is a very magical command. Let's learn how to use the kill command to restart Nginx.

If the machine is slow, Nginx can not kill the kill process when it restarts, and then execute it once. This type of restart is not particularly secure. If the configuration is incorrect, the restart will fail. You need to re-modify the configuration file and then start it again, which will take a while. However, for the http world, which is generally not very strict, this time will not cause too much loss, as long as it is not made at a critical moment. If you want to follow this restart method, I suggest to test it first.

Later I saw a more wonderful Nginx restart on nginx.net

kill -HUP $pid($pid is the process number of the nginx master process)

I generally use this

kill -HUP `cat /data/nginx/logs/nginx.pid`

The advantage of this way is to achieve "smooth restart" in ps-aux As you can see, nginx starts the new process first, and the old process still provides the service. After a while, the old process service is automatically closed after the end of the service, and the new process continues to serve. However, this method is also disadvantageous. If the configuration file is incorrect, or the resource conflicts, the restart fails, but nginx does not have any prompts! This will often find that the changed configuration file does not take effect and it is more difficult to find the problem. //www.45it.com

So, finally mixed the problem, got a nginx.sh, this version of nginx.sh still did not solve the problem of kill -HUP resource conflict, but solved The problem with the configuration file. For resource conflicts, for example, port 80 is occupied, and the log file directory is not created. Refer to the online practice and control with the following script:

#!/bin/sh BASE_DIR='/usr/local/' ${BASE_DIR}nginx/sbin/nginx -t -c ${BASE_DIR}nginx/Conf/nginx. conf >& ${BASE_DIR}nginx/logs/nginx.start info=`cat ${BASE_DIR}nginx/logs/nginx.start` if [ `echo $info

Copyright © Windows knowledge All Rights Reserved