The difference between nginx -s reload and service nginx restart

With several years of Nginxconsistent without questioning the difference between the two of them I am always thought restart command, but also when used with nginx -s reloadmore. This period of time is a Dockertoss Nginx, so I looked at Nginxthe official documents, suddenly found nginx -susing the command.

Official document: https://nginx.org/en/docs/beginners_guide.html

1. Grammar

nginx -s signal

signalThe value of is as follows:
stopfast shutdown, fast stop nginx
quit: graceful shutdown, no longer accept new requests, stop after the request being processed is completed (graceful shutdown)
reload: reloading the configuration file, reload the configuration file
reopen: reopening the log files, re-write the log files

2. The difference between the two

nginx -s reload(Hot reload): The Nginxservice will not be terminated, use the main process to check the configuration 如果配置文件语法正确,则主进程会启动一个新的工作进程处理新来的请求. The main process sends a message to the original worker process, notifying that the old process is not accepting requests, and exits after processing the existing request (graceful exit); if the syntax is incorrect, the old process continues to process the request.

service nginx restart(Restart): during the execution of this command is as follows, nginx -s stop-> nginxfirst Nginxquick stop (equal to service nginx stop), and then perform the startup commands (equivalent to service nginx start) start time will cause a brief interruption in service; if the configuration file syntax error, The problem is big, it may cause a longer interruption, and it may cause a large downtime.

3. Matters needing attention

  1. If the environment is formally required to modify the configuration file, first look at the original configuration file backup, and then making modifications; after the first modification is completed by nginx -twhether an error check the configuration file, if not, then nginx -s reloadheat load.

  2. If asked to stop Nginxor release Nginxa resource that we use service nginx stopor service nginx restartcommand, or are generally used nginx -s reload.

Personal blog: http://roc.havemail.cn/archives/892.html

Guess you like

Origin blog.csdn.net/peng2hui1314/article/details/108201715