how to set nginx access log format - zhongguogu/Linux GitHub Wiki
如何设置访问日志格式
nginx.conf
http{
log_format **access **' [$time_local] | $host | $remote_addr | $request | $request_time | $body_bytes_sent | $status |'
'| $upstream_addr | $upstream_response_time | $upstream_status |'
' "$http_referer" | "$http_user_agent" ';
access_log /var/log/nginx/access.log **access**;
error_log /var/log/nginx/error.log;
}
[18/Feb/2021:11:02:34 +0800] | 10.21.138.90 | 10.24.71.124 | GET /pdf/trans?id=3282442&insertTime=2021-02-18&source=em_pc&type=61173529492151d1577adf5e37c099.pdf HTTP/1.1 | 0.798 | 63 | 200 || 127.0.0.1:9056 | 0.798 | 200 | "-" | "Apache-HttpClient/4.5.2 (Java/1.8.0_102)"
日志格式介绍
$upstream_connect_time – The time spent on establishing a connection with an upstream server
$upstream_header_time – The time between establishing a connection and receiving the first byte of the response header from the upstream server
$upstream_response_time – The time between establishing a connection and receiving the last byte of the response body from the upstream server
$request_time – The total time spent processing a request
注意点
http{
access_log /var/log/nginx/access.log **access**;
}
指定access_log文件存放目录,也需要指定类型“access”(在http->log_format 定义的)
参考信息:https://docs.nginx.com/nginx/admin-guide/monitoring/logging/