Centos7开启nginx status

Centos 7开启nginx status

这段时间需要研究APM相关,整理到中间件部分,想到用zabbix来监控Nginx,一般情况下,中间件都有自己的计数器,我们只需要获取计数器的数值即可完成监控。

安装nginx

还是啰嗦一下,安装nginx,一条命令即可:

1
yum install nginx

配置文件路径:
默认配置:/etc/nginx/nginx.conf
可自建配置:/etc/nginx/conf.d/yourAPP.conf(需要修改nginx.conf最后的配置文件路径)

开启nginx status

开启很简单,在配置中增加:

1
2
3
4
5
6
7
location /ngx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

即可;
由于之前有帮开发搭建了.net core的环境,就直接在之前搭建的配置文件(LiabTest.conf)里面改了:
原文件:

1
2
3
4
5
6
7
8
9
10
11
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

增加status之后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /ngx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}

查看效果

重启nginx:

1
systemctl restart nginx

查看status:

1
curl http://127.0.0.1/ngx_status

看到信息:

1
2
3
4
5
[root@gtp1 conf.d]# curl http://127.0.0.1/ngx_status
Active connections: 1199
server accepts handled requests
158761 158761 158757
Reading: 0 Writing: 1195 Waiting: 4

nginx status详解

1
2
3
4
5
active connections – 活跃的连接数量
server accepts handled requests — 总共处理了158761个连接 , 成功创建158761次握手, 总共处理了158757个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
文章目录
  1. 安装nginx
  2. 开启nginx status
  3. 查看效果
  4. nginx status详解
|