温馨提示×

centos apache日志格式是啥

小樊
40
2026-09-27 07:39:00
栏目: 智能运维

在 CentOS 上,Apache(通常是 httpd)的日志格式主要在配置文件中定义,常见位置有:

  • /etc/httpd/conf/httpd.conf
  • /etc/httpd/conf.d/*.conf

一、默认日志格式(Common Log Format)

CentOS 中 Apache 默认一般使用 common 或 combined 格式。

1️⃣ common 格式

LogFormat "%h %l %u %t \"%r\" %>s %b" common

示例日志:

192.168.1.10 - - [10/Oct/2024:14:32:01 +0800] "GET /index.html HTTP/1.1" 200 2326

字段含义:

  • %h:客户端 IP
  • %l:远程登录名(通常为 -)
  • %u:认证用户(未登录为 -)
  • %t:时间
  • %r:请求行
  • %>s:响应状态码
  • %b:响应字节数

2️⃣ combined 格式(更常用)

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

示例日志:

192.168.1.10 - - [10/Oct/2024:14:32:01 +0800] "GET /index.html HTTP/1.1" 200 2326 "https://www.baidu.com/" "Mozilla/5.0"

多了:

  • Referer
  • User-Agent

二、日志文件位置

CentOS 上常见日志路径:

/var/log/httpd/access_log      # 访问日志
/var/log/httpd/error_log       # 错误日志

三、如何查看当前使用的日志格式

grep -E "LogFormat|CustomLog" /etc/httpd/conf/httpd.conf

四、自定义日志格式示例

LogFormat "%h %t \"%r\" %>s %b %D" myformat
CustomLog logs/access_log myformat
  • %D:请求处理时间(微秒)

如果你是想 分析日志 / 改格式 / 看某个字段含义,可以告诉我具体需求。

0 踩