CentOS 上 Apache 的日志格式,通常分 访问日志(access log) 和 错误日志(error log) 两类,下面说清楚常见情况和默认格式。
/var/log/httpd/access_log
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)"
客户端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 ...":浏览器/客户端信息LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
/var/log/httpd/error_log
[Wed Jan 21 10:32:15.123456 2026] [core:error] [pid 12345] [client 192.168.1.10:54321] AH00124: Couldn't find directive X
core, php, ssl)grep -i logformat /etc/httpd/conf/httpd.conf
grep -i customlog /etc/httpd/conf/httpd.conf
common:基础格式combined:含 Referer + UA(最常用)如果你是想 做日志分析 / 写正则 / 接 ELK / 改 JSON 格式,我可以直接给你示例。