分析 Apache 错误日志是排查 Web 服务器问题的关键步骤。下面从日志位置、结构、常见错误、分析思路几个方面系统说明。
/var/log/apache2/error.log # Debian / Ubuntu
/var/log/httpd/error_log # CentOS / RHEL
apachectl -S
grep ErrorLog /etc/apache2/apache2.conf
grep ErrorLog /etc/httpd/conf/httpd.conf
一条典型错误日志示例:
[Thu Jan 23 10:12:34.123456 2026] [core:error] [pid 1234] [client 1.2.3.4:5678]
AH00124: Request exceeded the limit of 10 internal redirects
| 字段 | 说明 |
|---|---|
[Thu Jan 23 10:12:34] |
时间 |
core:error |
模块 + 日志级别 |
pid 1234 |
进程 ID |
client 1.2.3.4 |
客户端 IP |
AH00124 |
Apache 错误码 |
| 后面内容 | 错误描述 |
Permission denied: AH00035
✅ 原因:
✅ 解决:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
如果是 SELinux:
setenforce 0 # 临时关闭测试
Request exceeded the limit of 10 internal redirects
✅ 原因:.htaccess 中 RewriteRule 写错
✅ 排查:
grep -R RewriteRule /var/www/html
PHP Fatal error: Call to undefined function
✅ 说明:
✅ 查看:
/var/log/php/error.log
AH00072: make_sock: could not bind to address [::]:80
✅ 解决:
netstat -tulnp | grep 80
systemctl stop nginx
Invalid command 'RewriteEngine'
✅ 解决:
a2enmod rewrite
systemctl restart apache2
tail -f /var/log/apache2/error.log
grep -i error /var/log/apache2/error.log
sed -n '/Jan 23 10:/,/Jan 23 11:/p' error.log
awk '{print $5}' error.log | sort | uniq -c | sort -nr
LogLevel error
# 或
LogLevel debug
⚠️ 生产环境不建议长期开 debug
你可以直接贴出:
我可以帮你逐行解读并给出解决方案 ✅