在 Nginx 的 access_log 中记录请求/响应大小

RJ0*_*J01 6 nginx

我需要在 access_log 中记录请求/响应大小(正文+标题)。知道如何在 nginx 中做到这一点吗?在 apache 中,我们可以使用 %I..%O...

Jau*_*ika 12

摘自ngx_http_log_module

$bytes_sent: 发送给客户端的字节数

$connection: 连接序列号

$connection_requests: 当前通过连接发出的请求数 (1.1.18)

$msec:以秒为单位的时间,日志写入时的毫秒分辨率

$pipe:“p”如果请求是流水线的,“。” 除此以外

$request_length: 请求长度(包括请求行、头部和请求体)

$request_time: 以毫秒为单位的请求处理时间;从客户端读取第一个字节到最后一个字节发送到客户端后写入日志之间经过的时间

$status: 响应状态

$time_iso8601: ISO 8601 标准格式的本地时间

$time_local: 通用日志格式的本地时间


Mar*_*555 7

我会在 nginx.conf 中使用这两个参数:

log_format perf '$remote_addr $status - $request_length $bytes_sent'

根据文档(http://wiki.nginx.org/HttpLogModule),$request_length这只是请求的正文,但我已经确认它包含所有标头(我有一些 GET 请求,其中包含许多超过 1400 字节的 cookie总共)。$bytes_sent是发送到客户端的总字节数($body_sent与与 apache %B 兼容的字节数相反)。