nginx监控server和location的流量

文章介绍了如何通过nginx-module-vts模块监控Nginxserver和location的流量。首先从GitHub下载并重新编译Nginx,解决可能的依赖问题。接着,在nginx.conf中添加配置,设置代理location和流量状态显示。在遇到启动错误时,指定配置文件启动Nginx并重载配置。最后,访问特定URL查看流量统计信息,并提供了解除/status页面显示的方法。
摘要由CSDN通过智能技术生成

1.监控server和location的流量需要  nginx-module-vts  模块

GitHub - vozlt/nginx-module-vts: Nginx 虚拟主机流量状态模块https://github.com/vozlt/nginx-module-vts

下载  nginx-module-vts  直接复制粘贴即可
cd /root
git clone https://github.com/vozlt/nginx-module-vts.git

2.下载完成后重新编译一下nginx

 ./configure --add-module=/root/nginx-module-vts

如遇到此报错
./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library



安装  sudo yum install google-perftools google-perftools-devel  即可解决

3.在nginx.conf下添加以下内容

http {
    .
    .
   vhost_traffic_status_zone;



#代理的location添加  vhost_traffic_status_filter_by_set_key /25 /25::$server_name;    其中/25 /25要和location后面的保持一致
  
 location /25/ {
vhost_traffic_status_filter_by_set_key /25 /25::$server_name;
         rewrite ^/25/(.*)([^/])$ http://代理的IP/25/$1$2/ ;

        proxy_pass http://被代理的IP:8000/;

 
}



#代理的location添加  vhost_traffic_status_filter_by_set_key /status /status::$server_name;    其中/status /status要和location后面的保持一致

location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
             vhost_traffic_status_filter_by_set_key /status /status::$server_name;
        }

4.如启动nginx报以下错误

[root@test2 sbin]#nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

只需用-c指以下配置文件即可解决
[root@test2 sbin]#nginx -c /usr/local/nginx/conf/nginx.conf

[root@test2 sbin]#nginx -s reload  #最后在重启以下即可完成了

5.现在浏览器上访问一下代理的地址,在访问IP/status即可

6.如果不想要在浏览器上显示/status::192.....,需要添加以下配置

location /status {
            vhost_traffic_status_bypass_stats on;
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
vhost_traffic_status_filter_by_set_key /status /status::$server_name;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值