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