graceful restart of ngnix

During the research and development process, it is very common to modify the nginx configuration file nginx.conf, and nginx needs to be restarted. If we reload directly, there is a certain risk, we can do it by sending system signals to the nginx main process.

 

Step 1: Confirm that the syntax of the nginx configuration file is correct, otherwise nginx will not load the new configuration file.

If such a message appears, the configuration file is correct.

 

Step 2: Graceful Restart

kill -HUP nginx process number

kill -HUP ''/var/run/nginx.pid"

When nginx receives the HUP signal, it will try to parse the configuration file first (if specified, use the specified file, otherwise use the default), and if successful, apply the new configuration file (for example: reopen the log file or listen for socket), after that, nginx runs a new worker process and gracefully shuts down the old worker process, notifies the worker process to close the listening socket, but continues to serve the currently connected clients, after all clients' services are completed, the old work The process is shut down, and if the application of the new configuration file fails, nginx continues to work with the old configuration.

After a graceful restart, the nginx master does not change, but rebuilds the worker process.


The functions implemented by the HUP command and the nginx -s reload command are the same.

   

 

Supplementary content: Several signals of nginx

TERM,INT fast shutdown

QUIT gracefully closes

HUP graceful restart, reload configuration file

USR1 reopens the log file, which is more useful when cutting logs

USR2 smooth upgrade executable program

WINCH gracefully shuts down worker processes

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931228&siteId=291194637