nginx can be controlled with signals.The process ID of the master process is written to the file/usr/local/nginx/logs/nginx.pid
by default.This name may be changed at configuration time, or innginx.conf
using thepiddirective.The master process supports the following signals:
TERM, INT fast shutdown QUIT graceful shutdown HUP changing configuration,keeping up with a changed time zone (only for FreeBSD and Linux),starting new worker processes with a new configuration,graceful shutdown of old worker processes USR1 re-opening log files USR2 upgrading an executable file WINCH graceful shutdown of worker processes
Individual worker processes can be controlled with signals as well,though it is not required.The supported signals are:
TERM, INT fast shutdown QUIT graceful shutdown USR1 re-opening log files WINCH abnormal termination for debugging(requires debug_points to be enabled)
Changing Configuration
In order for nginx to re-read the configuration file, a HUPsignal should be sent to the master process.The master process first checks the syntax validity, then triesto apply new configuration, that is, to open log files and newlisten sockets.If this fails, it rolls back changes and continues to workwith old configuration.If this succeeds, it starts new worker processes, andsends messages to old worker processes requesting them toshut down gracefully.Old worker processes close listen sockets and continue to serviceold clients.After all clients are serviced, old worker processes are shut down.
Let’s illustrate this by example.Imagine that nginx is run on FreeBSD 4.x and the command,,
BSD格式的,linux测试时,axw前面不用加-号,加了会提示warning
ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'
produces the following output:
PID PPID USER %CPU VSZ WCHAN COMMAND
33126 1 root 0.0 1148 pause nginx: master process /usr/local/nginx/sbin/nginx
33127 33126 nobody 0.0 1380 kqread nginx: worker process (nginx)
33128 33126 nobody 0.0 1364 kqread nginx: worker process (nginx)
33129 33126 nobody 0.0 1364 kqread nginx: worker process (nginx)
If HUP is sent to the master process, the output becomes:
PID PPID USER %CPU VSZ WCHAN COMMAND
33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx
33129 33126 nobody 0.0 1380 kqread nginx: worker process is shutting down (nginx)
33134 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)
33135 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)
33136 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)
One of the old worker processes with PID 33129 still continues to work.After some time it exits:
PID PPID USER %CPU VSZ WCHAN COMMAND
33126 1 root 0.0 1164 pause nginx: master process /usr/local/nginx/sbin/nginx
33134 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)
33135 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)
33136 33126 nobody 0.0 1368 kqread nginx: worker process (nginx)
后面还有下次再看,经常看英文,脑子有点儿大