温馨提示×

nginx怎么读取客户端连接数

小亿
84
2023-12-16 14:18:56
栏目: 编程语言

Nginx可以使用ngx_http_stub_status_module模块来读取客户端连接数。该模块提供了一个状态页面,显示了当前的连接数、请求数、处理时间等信息。

要启用ngx_http_stub_status_module模块,需要在Nginx的配置文件中添加以下内容:

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

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

接下来,可以使用curl或者浏览器等工具来访问http://localhost/nginx_status,就可以看到当前的连接数等信息了。

示例输出:

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

其中,Active connections表示当前的活动连接数。

0