温馨提示×

centos apache日志啥格式

小樊
37
2026-10-03 04:34:25
栏目: 智能运维

CentOS 上 Apache 的日志格式,通常分 访问日志(access log) 和 错误日志(error log) 两类,下面说清楚常见情况和默认格式。


一、访问日志(Access Log)

1️⃣ 日志位置(常见)

/var/log/httpd/access_log

2️⃣ 默认日志格式(CentOS / RHEL)

CentOS 默认使用的是 combined 格式(最常见):

192.168.1.10 - - [21/Jan/2026:10:32:15 +0800] "GET /index.html HTTP/1.1" 200 2326 "http://example.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"

3️⃣ 各字段含义

客户端IP - 远程用户 - [时间] "请求方法 URL 协议" 状态码 响应大小 "Referer" "User-Agent"
  • 192.168.1.10:客户端 IP
  • -:身份校验用户(无则为 -)
  • -:RFC 1413 身份(一般 -)
  • [21/Jan/2026:10:32:15 +0800]:时间
  • "GET /index.html HTTP/1.1":请求行
  • 200:HTTP 状态码
  • 2326:返回字节数
  • "http://example.com/":来源页(Referer)
  • "Mozilla/5.0 ...":浏览器/客户端信息

4️⃣ 常见日志格式定义(httpd.conf)

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

二、错误日志(Error Log)

1️⃣ 日志位置

/var/log/httpd/error_log

2️⃣ 默认格式

[Wed Jan 21 10:32:15.123456 2026] [core:error] [pid 12345] [client 192.168.1.10:54321] AH00124: Couldn't find directive X

3️⃣ 字段说明

  • 时间
  • 模块名(如 core, php, ssl)
  • 日志级别(error / warn / notice)
  • 进程 ID
  • 客户端 IP(如果有)
  • 具体错误信息

三、如何确认当前格式

grep -i logformat /etc/httpd/conf/httpd.conf
grep -i customlog /etc/httpd/conf/httpd.conf

四、常见格式类型

  • common:基础格式
  • combined:含 Referer + UA(最常用)
  • 自定义 JSON(用于 ELK / 日志分析)

如果你是想 做日志分析 / 写正则 / 接 ELK / 改 JSON 格式,我可以直接给你示例。

0 踩