Nginx模块配置教程:状态监控模块ngx_http_stub_status_module

2020年11月23日14:59:04 发表评论 1,396

ngx_http_stub_status_module模块是Nginx中用来统计Nginx服务所接收和处理的请求数量,只要在编译安装Nginx的时候加上参数--with-http_stub_status_module就可以开启该功能,如果编译时没有加该参数的话可以重新编译安装一次,不会影响原有的配置文件。

开启ngx_http_stub_status_module模块的方法:

1、编译nginx.conf,增加以下内容:
server {
listen 80;
location /status {
stub_status on ;
access_log off;
}
}
2、通过URL访问/status页面进行测试,即可打开监控页面,如图:
active connections:当前 Nginx 正在处理的活动连接数.
server accepts handled requests:总共处理53个连接,成功创建53次握手,前2个数字一样代表没有失败连接,总过处理了66次请求(因为一个连接可能会有多个请求)。
Reading:Nginx读取到客户端的Header信息数
Writing:Nginx返回给客户端的Header信息数
Waiting:开启Keep-alive长连接后,既没有读也没有写的信息数

3、这种监控页面通常不允许随意访问,所以需要配置访问控制,对访问该页面的人进行身份验证。使用yum安装好httpd-tools后,使用htpasswd命令生成身份验证所需文件,命令如下:

4、编辑nginx.conf指定验证用户的身份信息配置文件:
server {
listen 80;
location /status {
stub_status on ;
access_log off;auth_basic "Nginx_status";
auth_basic_user_file /usr/local/nginx/conf/htpasswd_nginx;
}
}

5、现在再访问测试,已经需要我们定义好的用户名密码才能登陆了

 

    发表评论

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: