nginx源码编译
下载nginx-module-vts:git clone git://github.com/vozlt/nginx-module-vts.git 并上传到机器上
下载openssl-1.0.2k:https://www.openssl.org/source/old/1.0.2/ 并上传到机器上
安装编译依赖:yum -y install pcre-devel zlib-devel
编译命令:
./configure --prefix=/home/maintain/nginx --conf-path=/home/shared/nginx/conf/nginx.conf --pid-path=/home/shared/nginx/logs/nginx.pid --error-log-path=/home/shared/nginx/logs/error.log --with-http_ssl_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --with-http_v2_module --with-stream --with-openssl=/home/maintain/openssl-1.0.2k/openssl-1.0.2k --add-module=/home/maintain/nginx-module-vts
make (如果是全新编译安装可以用make install)
编译出的nginx二进制文件在 objs目录下
nginx-module-vts 模块可以统计nginx的很多信息,比如5xx等状态码数据,
具体配置如下:
http块添加
vhost_traffic_status_zone shared:vhost_traffic_status:64m;
server块添加
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
然后{nginxip}/status即可查看到状态信息
如果要用promethues监控nginx,可以使用{nginxip}/status/format/promethues作为metrics_path
如果需要过滤某个location的5xx统计,可以在location下添加vhost_traffic_status_bypass_stats on; 即可