温馨提示×

debian nginx日志格式是什么

小樊
43
2026-09-10 07:15:12
栏目: 智能运维

在 Debian 上,Nginx 的日志格式通常指的是 access_log(访问日志)error_log(错误日志) 的格式。


一、access_log(访问日志)

1. 默认日志格式(combined)

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"';

2. 默认日志内容示例

192.168.1.10 - - [12/Jun/2024:10:22:31 +0800] "GET /index.html HTTP/1.1" 200 612 "-" "Mozilla/5.0"

3. 各字段含义

字段 含义
$remote_addr 客户端 IP
$remote_user 认证用户(无则为 -
[$time_local] 本地时间
$request 请求行(方法 + URL + 协议)
$status HTTP 状态码
$body_bytes_sent 响应体大小(字节)
$http_referer 来源页面
$http_user_agent 客户端浏览器/代理

二、error_log(错误日志)

1. 日志级别

error_log /var/log/nginx/error.log warn;

级别(从低到高):

debug < info < notice < warn < error < crit < alert < emerg

2. 默认错误日志示例

2024/06/12 10:22:31 [error] 1234#1234: *5 open() "/var/www/html/test.html" failed (2: No such file or directory)

3. 字段说明

时间 [级别] 进程ID: *连接ID 错误信息

三、Debian 中默认日志路径

/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 默认配置文件位置如何修改日志格式,或 如何按虚拟主机分离日志,可以继续问我。

0