nginx 學習筆記 3 nginx管理

2021-06-19 21:04:17 字數 2410 閱讀 4511

nginx可以通過向其傳送訊號來進行管理。預設情況下主程序的程序id寫到檔案/usr/local/nginx/logs/nginx.pid中。當然也可以在配置檔案中自定義該pid檔案,自定義使用pid指令來進行修改。主程序支援如下訊號:

term, int

fast shutdown

quit

graceful shutdown

hupchanging 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

儘管不是必須,單個的工作程序同樣可以通過下列訊號進行控制。工作程序支援如下訊號:

term, int

fast shutdown

quit

graceful shutdown

usr1

re-opening log files

winch

debug_points

改變配置檔案

為使nginx重新讀取配置檔案,可以想主程序傳送乙個hub訊號。主程序首先檢測語法的有效性,然後嘗試應用到新的配置中即開啟日誌檔案和新的監聽套接字:若失敗,主程序回滾到改變前的配置,並繼續使用舊的配置執行。若成功則開啟新的工作程序,給舊的工作程序傳送完整性關閉命令,舊的工作程序關閉監聽套接字,繼續處理舊的請求並返回給客戶端,當所有的客戶端請求處理完後,舊的工作程序關閉。

舉個例子,假定nginx執行在freebsd 4.x之上,命令如下:

ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|pid)'
列印出如下內容:

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的舊工作程序正在處理請求中。過一段時間後再觀察,發現它已經關閉掉了:

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)

---出去一段時間

nginx學習 3 Nginx 核心配置詳解

說明 main 配置影響nginx全域性的指令。一般有執行nginx伺服器的使用者組,nginx程序pid存放路徑,日誌存放路徑,配置檔案引入,允許生成worker process數等。event 配置影響nginx伺服器或與使用者的網路連線。有每個程序的最大連線數,選取哪種事件驅動模型處理連線請求...

3 Nginx日誌管理 含Nginx日誌切割

我們觀察nginx的server段,可以看到如下類似資訊 access log logs host.access.log main 這說明 該server,它的訪問日誌的檔案是 logs host.access.log 使用的格式 main 格式.除了main格式,你可以自定義其他格式.main格式...

Nginx的配置與部署(3)Nginx請求處理機制

本文為您解讀,nginx是如何處理請求的,讓你從邏輯上有乙個清晰的認識。處理訪問到 nginx 所在 ip 位址的請求,並且這些請求的 http 頭資訊中的 host 為所要處理的網域名稱 如下以80埠為例 如下幾個 server 就對應響應的請求 server server server如果不主動...