nginx日志配置
2022年5月31日小于 1 分钟约 153 字
HTTP请求变量
- arg_PARAMETER # request请求参数
- http_HEADER # request请求的header
- 例如:
$http_user_agent
- 例如:
- sent_http_HEADER # response响应的header
- nginx变量
- remote_addr # 客户端ip
# >>> vim /etc/nginx/nginx.conf
# nginx的错误日志路径
error_log /var/log/nginx/error.log warn;
# ...
http {
# 定义日志类型'main'
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# 使用'main'格式记录日志
access_log /var/log/nginx/access.log main;
}
自定义main日志类型详解:
' 客户端地址 - 认证用户名 [时间] "request请求头" '
' 返回的状态码 响应的body大小 “访问的上一页地址” '
' "用户代理" "携带的http信息" '