Nginx高级配置-状态页配置

              Nginx高级配置-状态页配置

                                       作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

  建议将nginx的监控状态的值通过zabbix或者Open-Falcon之类的监控工具来监控状态,并将数据在数据库中落地,便于查找历史信息以作参考对比。

 

 

一.编辑配置文件

1>.检查编译安装nginx的时候的参数是否包含"--withhttp_stub_status_module",因为状态页是基于nginx模块ngx_http_auth_basic_module实现

[root@node101.yinzhengjie.org.cn ~]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/yinzhengjie/softwares/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

2>.编辑主配置文件

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf/nginx.conf
worker_processes  4;
worker_cpu_affinity 00000001 00000010 00000100 00001000; 

events {
    worker_connections  100000;
    use epoll;
    accept_mutex on;
    multi_accept on; 
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    gzip  on;
    charset utf-8;

    #最大缓存10000个文件,非活动数据超时时长60s
    open_file_cache max=10000 inactive=60s;
    #每间隔60s检查一下缓存数据有效性
    open_file_cache_valid 60s;
    #60秒内至少被命中访问5次才被标记为活动数据
    open_file_cache_min_uses 5;
    #缓存错误信息
    open_file_cache_errors on;

    #隐藏Nginx server版本。
    server_tokens off;

    #当文件大于等于给定大小时,同步(直接)写磁盘,而非写缓存。
    directio 4m;

    #上传文件相关参数
    client_max_body_size 10m;
    client_body_buffer_size 16k;
    client_body_temp_path /yinzhengjie/data/web/nginx/temp 1 2 2;
   

    #IE系列的浏览器禁用长连接,默认就是禁用了IE的长连接功能.
    keepalive_disable msie6;

    #开启长连接后,返回客户端的会话保持时间为60s,单次长连接累计请求达到指定次数请求或65秒就会被断开,后面的60为发送给客户端应答报文头部中显示的超时时间设置为60s:如不设置
客户端将不显示超时时间。    keepalive_timeout  65 60;

    #在一次长连接上所允许请求的资源的最大数量
    keepalive_requests 3;
    
    #导入其他路径的配置文件
    include /yinzhengjie/softwares/nginx/conf.d/*.conf;
}

[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 

3>.编辑子配置文件

[root@node101.yinzhengjie.org.cn ~]# cat /yinzhengjie/softwares/nginx/conf.d/share.conf 
server {
    listen 80;
    server_name node101.yinzhengjie.org.cn;

    location / {
        root /yinzhengjie/data/web/nginx/static;
        index index.html;
    }

    location /nginx_status {
        stub_status;
        allow 172.30.1.108;
    deny all;
    }
}
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -t
nginx: the configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /yinzhengjie/softwares/nginx/conf/nginx.conf test is successful
[root@node101.yinzhengjie.org.cn ~]# 

4>.重新加载配置文件

[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root      2840     1  0 09:37 ?        00:00:00 nginx: master process nginx
nginx     5503  2840  0 16:41 ?        00:00:00 nginx: worker process
nginx     5504  2840  0 16:41 ?        00:00:00 nginx: worker process
nginx     5505  2840  0 16:41 ?        00:00:00 nginx: worker process
nginx     5506  2840  0 16:41 ?        00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# nginx -s reload
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ps -ef | grep nginx | grep -v grep
root      2840     1  0 09:37 ?        00:00:00 nginx: master process nginx
nginx     5704  2840  1 17:23 ?        00:00:00 nginx: worker process
nginx     5705  2840  1 17:23 ?        00:00:00 nginx: worker process
nginx     5706  2840  1 17:23 ?        00:00:00 nginx: worker process
nginx     5707  2840  1 17:23 ?        00:00:00 nginx: worker process
[root@node101.yinzhengjie.org.cn ~]# 

 

二.客户端访问

1>.客户端访问状态页的URL 

2>.状态页输出信息说明

[root@node108.yinzhengjie.org.cn ~]# curl http://node101.yinzhengjie.org.cn/nginx_status
Active connections: 1 
server accepts handled requests
 100873 100873 100249 
Reading: 0 Writing: 1 Waiting: 0 
[root@node108.yinzhengjie.org.cn ~]# 
[root@node108.yinzhengjie.org.cn ~]# 


状态页用于输出nginx的基本状态信息,下面是关于输出信息的详细说明:
  Active connections: 
    当前处于活动状态的客户端连接数,包括连接等待空闲连接数。当这个数值非常大时,我们得考虑nginx后端提供的web服务以及数据库性能上是否可以hold住。   accepts:
    统计总值,Nginx自启动后已经接受的客户端请求的总数。对于运维来说,并没有太大的参考一样,因为如果我们长期不重启nginx服务,那么这个数字可能会很大。   handled:
    统计总值,Nginx自启动后已经处理完成的客户端请求的总数,通常等于accepts,除非有因worker_connections限制等被拒绝的连接。同理,这个参数的参考意义对运维人员来说也不大。   requests:
    统计总值,Nginx自启动后客户端发来的总的请求数。这个数值会很大,因为一个链接会有多个请求。   Reading:
    当前状态,正在读取客户端请求报文首部的连接的连接数。即表示正在和nginx建立连接但还没有建立成功,如果这个数字很大的话,说明你的nginx服务器处理速度相对比较慢,和用户建立连接都需要排队了,所以得考虑做优化。   Writing:
    当前状态,正在向客户端发送响应报文过程中的连接数。如果这个数字过大,可能是响应报文给客户端可能会涉及到静态资源(比如js,css,html)获取速度较慢(因为有资源是在本地服务器,有的是在后端服务器,有的资源可能没有及时响应)会导致整个响应过程很慢。   Waiting:
    当前状态,正在等待客户端发出请求的空闲连接数,开启 keep-alive的情况下,这个值等于active – (reading+writing),

 

posted @ 2019-12-15 20:24  尹正杰  阅读(793)  评论(0编辑  收藏  举报