nginx怎么讀取客戶端連接數(shù)

小億
99
2023-12-16 14:18:56
欄目: 編程語言

Nginx可以使用ngx_http_stub_status_module模塊來讀取客戶端連接數(shù)。該模塊提供了一個(gè)狀態(tài)頁面,顯示了當(dāng)前的連接數(shù)、請(qǐng)求數(shù)、處理時(shí)間等信息。

要啟用ngx_http_stub_status_module模塊,需要在Nginx的配置文件中添加以下內(nèi)容:

location /nginx_status {
    stub_status on;
    access_log off;
    allow 127.0.0.1; # 限制只能本地訪問
    deny all; # 禁止其他IP訪問
}

然后重新加載Nginx配置文件。

接下來,可以使用curl或者瀏覽器等工具來訪問http://localhost/nginx_status,就可以看到當(dāng)前的連接數(shù)等信息了。

示例輸出:

Active connections: 291 
server accepts handled requests
 16630948 16630948 31070487 
Reading: 6 Writing: 179 Waiting: 106 

其中,Active connections表示當(dāng)前的活動(dòng)連接數(shù)。

0