启用nginx status状态详解

凉白开 Nginx16181,76391字数 738阅读2分27秒阅读模式

nginxphp-fpm一样内建了一个状态页,对于想了解nginx的状态以及监控nginx非常有帮助。为了后续的zabbix监控,我们需要先了解nginx状态页是怎么回事。

1. 启用nginx status配置

在默认主机里面加上location或者你希望能访问到的主机里面。文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-status-detail/

server {
    listen  *:80 default_server;
    server_name _;
    location /ngx_status 
    {
        stub_status on;
        access_log off;
        #allow 127.0.0.1;
        #deny all;
    }
}

2. 重启nginx

请依照你的环境重启你的nginx文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-status-detail/

# service nginx restart

3. 打开status页面

# curl http://127.0.0.1/ngx_status
Active connections: 11921 
server accepts handled requests
 11989 11989 11991 
Reading: 0 Writing: 7 Waiting: 42

4. nginx status详解

active connections – 活跃的连接数量
server accepts handled requests — 总共处理了11989个连接 , 成功创建11989次握手, 总共处理了11991个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-status-detail/

5. 完成

下篇文章我们将使用zabbix监控nginx文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-status-detail/ 文章源自运维生存时间-https://www.ttlsa.com/nginx/nginx-status-detail/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
凉白开
  • 本文由 发表于 18/05/2014 01:00:05
  • 转载请务必保留本文链接:https://www.ttlsa.com/nginx/nginx-status-detail/
评论  16  访客  14
    • 匿名
      匿名 0

      楼主,Active connections和Reading: 0 Writing: 1 Waiting: 3都可以获取到正常到值,但是zabbix里server accepts handled requests获取到三个值都是0.

        • 匿名
          匿名 9

          @ 匿名 我也遇到这个问题,请问如何解决?agent_get 可以正常获取数据。

        • Jilong
          Jilong 0

          我已经配置好了,不过发现个问题:
          1. 我的环境是测试环境目前没有外界访问,但是发现server accepts handled requests 这个指标一直在涨,这是正常的么
          2. 如下是我curl的输出:Active Connection 1是指哪个连接呢?是脚本产生的么?
          curl http://127.0.0.1:8081/nginx_status
          Active connections: 1
          server accepts handled requests
          4067 4067 3509
          Reading: 0 Writing: 1 Waiting: 0

            • XiGua
              XiGua 9

              @ Jilong 有同样的困惑,找到这里来了,希望有人能给个答复。 :neutral:

            • longdechuanren517
              longdechuanren517 4

              rewrite ^(.*) https://$server_name$1 permanent; 我的url重新就写了这么一条信息

                • 运维生存时间
                  运维生存时间 7

                  @ longdechuanren517 如果写在server里location之外,肯定不行的

                    • longdechuanren517
                      longdechuanren517 4

                      @ 运维生存时间 嗯嗯,我后来重新再写过虚拟主机,然后脚本监控的时间监控别的端口就行。我之前还以为只能够监控80端口呢。多谢

                  • longdechuanren517
                    longdechuanren517 4

                    我想问下我的nginx开启了ssl证书认证,然后按照文档去做的时候没有显示状态,显示的是页面代码。这是为什么。有没有可能和我的url做转发有关系

                    • 木头人SeanZhang
                      木头人SeanZhang 9

                      请问斑竹,nginx的每个虚拟主机能够独立开启状态监控,并显示各自网址的连接状态吗?
                      我的多个网址开启了监控以后,连接状态是一样的,这样就没有意义了。

                      • sdhui
                        sdhui 0

                        nginx stub_status 请问可以按每个虚拟主机来分配吗? 独立开显示,之前看到用$host区分,但没成功…

                        • 牧童Damian
                          牧童Damian 9

                          mark
                          –with-http_stub_status_module

                        评论已关闭!