nginx 学习笔记(3) nginx管理

nginx能够经过向其发送信号来进行管理。默认状况下主进程的进程ID写到文件/usr/local/nginx/logs/nginx.pid中。固然也能够在配置文件中自定义该pid文件,自定义使用pid指令来进行修改。主进程支持以下信号:html

 

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

 

尽管不是必须,单个的工做进程一样能够经过下列信号进行控制。工做进程支持以下信号:nginx

 

TERM, INT fast shutdown
QUIT graceful shutdown
USR1 re-opening log files
WINCH abnormal termination for debugging (requires debug_points to be enabled)

 

                              改变配置文件web

为使nginx从新读取配置文件,能够想主进程发送一个HUB信号。主进程首先检测语法的有效性,而后尝试应用到新的配置中即打开日志文件和新的监听套接字:若失败,主进程回滚到改变前的配置,并继续使用旧的配置运行。若成功则开启新的工做进程,给旧的工做进程发送完整性关闭命令,旧的工做进程关闭监听套接字,继续处理旧的请求并返回给客户端,当全部的客户端请求处理完后,旧的工做进程关闭。ui

   举个例子,假定nginx运行在FreeBSD 4.X之上,命令以下:spa

 

ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'

 

打印出以下内容:debug

 

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)

 

向主进程发送HUP信号后,打印出以下内容:日志

 

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)

 

能够看到PID为33129的旧工做进程正在处理请求中。过一段时间后再观察,发现它已经关闭掉了:code

 

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)

 

 ---出去一段时间orm

相关文章
相关标签/搜索