首頁  >  文章  >  運維  >  nginx如何設定狀態監控

nginx如何設定狀態監控

王林
王林轉載
2023-05-28 23:06:311417瀏覽

Nginx有內建狀態頁,需要在編譯的時候指定參數--with-http_stub_status_module參數方可開啟。
也就是說,該功能是由http_stub_status_module模組提供,預設沒有載入。

設定檔範例

server{
    listen 80;
    server_name www.xxx.com;
    
    location /status/ {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        allow 192.168.10.0/24;
        deny all;
    }
}

設定說明

  • #location /status/這樣當存取/ status/時即可存取狀態頁內容。

  • stub_status on即開啟了狀態頁。

  • access_log off不記錄日誌

  • #allow和deny只允許指定IP和IP段訪問,因為這個頁面需要保護起來,並不公開,當然也可以做使用者認證。

測試和結果說明

测试命令:curl -x127.0.0.1:80 www.xxx.com/status/

结果如下:
Active connections: 1 
server accepts handled requests
 11 11 11 
Reading: 0 Writing: 1 Waiting: 0 

说明:
active connections – 活跃的连接数量
server accepts handled requests — 总共处理的连接数、成功创建的握手次数、总共处理的请求次数
需要注意,一个连接可以有多次请求。
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

以上是nginx如何設定狀態監控的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除