在 CentOS 上,Apache(通常是 httpd)的日志格式主要在配置文件中定义,常见位置有:
/etc/httpd/conf/httpd.conf/etc/httpd/conf.d/*.confCentOS 中 Apache 默认一般使用 common 或 combined 格式。
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:响应字节数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"
多了:
RefererUser-AgentCentOS 上常见日志路径:
/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:请求处理时间(微秒)如果你是想 分析日志 / 改格式 / 看某个字段含义,可以告诉我具体需求。