编程技术分享平台

网站首页 > 技术教程 正文

nginx实时记录请求状态信息(ngx_realtime_request_module)

xnh888 2024-09-28 03:07:57 技术教程 18 ℃ 0 评论

关于

ngx_realtime_request是nginx用来统计虚拟主机流量的模块, 首先和大家说下这个模块是基于域名的,将会记录这个域名的请求量、发送字节、返回http状态码的数量,特性如下:

  • 基于域名记录

  • 记录请求数据量

  • 记录发送、响应流量

  • 记录返回各种http状态码统计数据

1. 安装

# cd /usr/local/src/

# wget "http://nginx.org/download/nginx-1.4.2.tar.gz"

# tar -xzvf nginx-1.4.2.tar.gz

# wget https://github.com/magicbear/ngx_realtime_request_module/archive/master.zip -O ngx_realtime_request.zip

# unzip ngx_realtime_request.zip

# cd nginx-1.4.2/

# ./configure --prefix=/usr/local/nginx-1.4.2 --add-module=../ngx_realtime_request_module-master

# make

# make install

2. 指令(directives)

realtime_zonesize
语法: realtime_zonesize size
默认值: 4m
配置块: http
设置slab大小

realtime_request
语法: realtime_request [on/off]
默认值: none
配置块: location
开启统计

3. 配置实例

http {

realtime_zonesize 16m;

server {

server_name www.ttlsa.com

location ~ /ttlsa-rt-status {

realtime_request on;

}

}

}

4. 测试

访问http://www.ttlsa.com几次,制造几个404和200等等

查看状态http://www.ttlsa.com/ttlsa-rt-status如下图

ngx_realtime_request

上图解释:

uptime:18 ->nginx运行了18秒
version:0.5 -> 当前插件版本
host:当前统计的域名,如果这台服务器有多个域名,会显示多行
request:请求量8个
recv:接收5294字节
send:发送2043字节
20x:响应了7次20x的状态码
30x:返回了0次30x
40x:返回了1次40xhttp状态码(我测试的404)
50x:返回了0次50x

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表