在 CentOS 上,Apache(通常是 httpd)的日志主要用来排查访问情况、错误原因和性能问题。下面从日志位置、常见日志类型、格式解读、实用分析命令几个方面说明。
CentOS 下 Apache 一般叫 httpd,日志默认在:
/var/log/httpd/
常见文件:
access_log:访问日志error_log:错误日志ssl_access_log / ssl_error_log:HTTPS 相关(如果启用 SSL)典型一行:
192.168.1.10 - - [12/Apr/2025:10:22:31 +0800] "GET /index.html HTTP/1.1" 200 2326 "https://example.com/" "Mozilla/5.0"
逐项说明:
| 字段 | 含义 |
|---|---|
| 192.168.1.10 | 客户端 IP |
| - | 远程登录名(通常为 -) |
| - | 认证用户(未登录为 -) |
| [12/Apr/2025:10:22:31 +0800] | 时间(含时区) |
| “GET /index.html HTTP/1.1” | 请求方法、URL、协议 |
| 200 | HTTP 状态码 |
| 2326 | 响应字节数 |
| “https://example.com/” | Referer(来源页) |
| “Mozilla/5.0” | User-Agent(浏览器/客户端) |
200:成功301 / 302:重定向304:未修改(缓存)403:禁止访问(权限问题)404:页面不存在500:服务器内部错误502 / 503 / 504:后端或网关问题示例:
[Sun Apr 12 10:25:01.123456 2025] [core:error] [pid 1234] [client 192.168.1.10:54321] AH00124: Request exceeded the limit of 10 internal redirects
结构说明:
core, php, ssl)error, warn, notice)常见错误:
Permission denied → 文件/目录权限问题File does not exist → 路径错误client denied by server configuration → Apache 配置限制PHP Fatal error → 应用层问题tail -f /var/log/httpd/access_log
tail -f /var/log/httpd/error_log
awk '{print $1}' access_log | sort | uniq -c | sort -nr | head
awk '{print $9}' access_log | sort | uniq -c | sort -nr
grep " 404 " access_log
grep "192.168.1.10" access_log
Apache 主配置:
/etc/httpd/conf/httpd.conf
相关指令:
CustomLog logs/access_log combined
ErrorLog logs/error_log
LogLevel warn
可修改日志格式或级别。
如果你愿意,可以:
我可以直接帮你逐行分析。