1. 默认格式:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
(1). 参数说明:
|参数|说明|
|—|—|—|
|remote_user | 客户端用户名称 | —
|request | 请求的URI和HTTP协议 | “GET /article-10000.html HTTP/1.1”
|body_bytes_sent | 发送给客户端文件内容大小 | 1547
|http_user_agent | 用户终端浏览器等信息 | “Mozilla/4.0 …
|$request_time | 整个请求的总时间 | 0.205
2. 自定义log_format:
(1). 自定义log_format:
vim /etc/nginx/nginx.conf
http
{
...
log_format request '$remote_addr - $remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
...
}
(2). 给web网站分配log_format:
server
{
...
access_log /etc/logs/xxx.log request;
error_log /etc/logs/xxx.error.log;
# 不指定log_format,则使用的默认的log_format.
}
(3). 两个时间的疑问?
- $request_time:
a. request processing time in seconds with a milliseconds resolution(1.3.9, 1.2.6);time elapsed since the first bytes were read from the client.
b. 这个时间是从Nginx接收到客户端第一个字节的数据开始计时的,包含了接收数据、等待响应的时间. - $upstream_response_time:
a. keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
b. 这个时间是Nginx等待后端程序响应的时间.