在 Debian 上,Nginx 的日志格式通常指的是 access_log(访问日志) 和 error_log(错误日志) 的格式。
Debian 中 Nginx 默认使用 combined 格式,定义通常位于:
/etc/nginx/nginx.conf
默认定义类似:
log_format combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
192.168.1.10 - - [12/Jun/2024:10:22:31 +0800] "GET /index.html HTTP/1.1" 200 612 "-" "Mozilla/5.0"
| 字段 | 含义 |
|---|---|
$remote_addr |
客户端 IP |
$remote_user |
认证用户(无则为 -) |
[$time_local] |
本地时间 |
$request |
请求行(方法 + URL + 协议) |
$status |
HTTP 状态码 |
$body_bytes_sent |
响应体大小(字节) |
$http_referer |
来源页面 |
$http_user_agent |
客户端浏览器/代理 |
error_log /var/log/nginx/error.log warn;
级别(从低到高):
debug < info < notice < warn < error < crit < alert < emerg
2024/06/12 10:22:31 [error] 1234#1234: *5 open() "/var/www/html/test.html" failed (2: No such file or directory)
时间 [级别] 进程ID: *连接ID 错误信息
/var/log/nginx/access.log
/var/log/nginx/error.log
log_format json_log escape=json '{'
'"time":"$time_local",'
'"remote_addr":"$remote_addr",'
'"request":"$request",'
'"status":$status,'
'"body_bytes":$body_bytes_sent'
'}';
access_log /var/log/nginx/access.log json_log;
如果你是想看 Debian 默认配置文件位置、如何修改日志格式,或 如何按虚拟主机分离日志,可以继续问我。