在 Debian 上,Apache 的日志格式主要涉及 访问日志(access log) 和 错误日志(error log),常见配置在 /etc/apache2/ 目录下。
下面分几部分说明:日志在哪、格式是什么、怎么看、怎么改。
Debian 默认路径:
/var/log/apache2/
常见文件:
access.log:访问日志error.log:错误日志other_vhosts_access.log:虚拟主机访问日志(如果启用)Debian 默认使用 combined 格式,一行示例:
192.168.1.10 - - [12/Jan/2026:10:22:31 +0800] "GET /index.html HTTP/1.1" 200 2326 "https://example.com/" "Mozilla/5.0"
含义逐段解释:
| 字段 | 说明 |
|---|---|
192.168.1.10 |
客户端 IP |
- |
远程日志名(通常为空) |
- |
认证用户(未登录为 -) |
[12/Jan/2026:10:22:31 +0800] |
时间(日/月/年:时:分:秒 时区) |
"GET /index.html HTTP/1.1" |
请求方法、路径、协议 |
200 |
HTTP 状态码 |
2326 |
响应字节数 |
"https://example.com/" |
Referer(来源页) |
"Mozilla/5.0" |
User-Agent(浏览器/客户端) |
common 格式(比 combined 少 Referer 和 UA):
192.168.1.10 - - [12/Jan/2026:10:22:31 +0800] "GET / HTTP/1.1" 200 2326
示例:
[Mon Jan 12 10:22:31.123456 2026] [core:error] [pid 1234] [client 192.168.1.10:54321] AH00124: Request exceeded the limit of 10
解释:
core, php7, ssl 等)error, warn, notice)在 Debian 中通常在:
/etc/apache2/apache2.conf
/etc/apache2/conf-enabled/*.conf
查找格式定义:
grep -R "LogFormat" /etc/apache2/
示例:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
常用变量说明:
%h:客户端 IP%t:时间%r:请求行%>s:状态码%b:响应大小%{Referer}i:Referer%{User-Agent}i:UA虚拟主机中:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
# 实时查看访问日志
tail -f /var/log/apache2/access.log
# 查看错误
tail -f /var/log/apache2/error.log
# 统计访问最多的 IP
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
# 查看 500 错误
grep " 500 " access.log
/var/log/apache2/combined 格式LogFormat 定义,站点用 CustomLog 指定如果你愿意,可以贴一段你的 具体日志内容,我可以帮你逐行解读。