Apache 日志突然变大,通常不是单一原因,而是访问量、配置、攻击或程序异常等因素叠加。下面按最常见 → 较少见给你一个系统排查思路,并给出对应解决办法。
排查方法:
wc -l access.log
tail -f access.log
看什么:
✅ 如果访问量真的变大 → 日志变正常
这是日志暴涨的第一大元凶
常见特征:
/wp-admin、/phpMyAdmin、/.env排查:
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
✅ 如果看到某个 IP 几千几万次 → 被攻击
解决:
iptables -A INPUT -s 1.2.3.4 -j DROP
不是 access.log,而是 error.log 突然变大
常见原因:
排查:
tail -n 100 error.log
典型危险日志:
PHP Notice:
PHP Warning:
File does not exist:
Request exceeded the limit of 10 internal redirects
✅ 解决:
display_errors = Off
log_errors = On
error_reporting = E_ALL & ~E_NOTICE
这是最容易被忽略的
症状:
检查:
ls -lh /var/log/httpd/
ls -lh /var/log/apache2/
检查 logrotate:
cat /etc/logrotate.d/apache2
✅ 正确示例:
/var/log/apache2/*.log {
daily
rotate 30
compress
missingok
notifempty
create 644 www-data www-data
postrotate
systemctl reload apache2
endscript
}
✅ 手动轮转测试:
logrotate -vf /etc/logrotate.d/apache2
LogLevel debug
✅ 会记录大量内部信息,日志暴涨
建议:
LogLevel warn
mod_dumpiomod_security(规则太激进)mod_rewrite 日志✅ 检查:
apache2ctl -M
✅ 特征:
✅ 解决:
tail -f access.log
awk '{print $7}' access.log | sort | uniq -c | sort -nr | head
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head
: > access.log
: > error.log
CustomLog /dev/null combined
Apache 日志突然变大,90% 是:访问量异常 + 攻击 + 错误日志失控 + 没有轮转。
如果你愿意,可以把下面信息贴出来,我可以直接帮你判断是哪一种:
tail -n 50 access.logtail -n 50 error.log我可以给你精确到行的解决方案。