在 Ubuntu 上,Apache 日志(通常是 access.log 和 error.log)变得过大,一般由以下几类原因造成:
正常高访问量
logrotate 未生效)爬虫 / 机器人频繁访问
被攻击或扫描
wp-login.php、/admin 等)LogLevel 设置过低(如 debug、info)常见配置:
LogLevel warn
不建议长期使用 debug
Ubuntu 默认有 logrotate,但可能:
检查:
ls -lh /var/log/apache2/
cat /etc/logrotate.d/apache2
访问日志格式过详细
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
如果不需要 Referer / User-Agent,可简化
记录了静态资源
<FilesMatch> 关闭du -sh /var/log/apache2/*
tail -f /var/log/apache2/access.log
logrotate -d /etc/logrotate.d/apache2
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!dontlog
/etc/logrotate.d/apache2 中:
daily
missingok
rotate 14
compress
delaycompress
notifempty
如果你愿意,可以贴出:
apache2.conf 或虚拟主机日志配置我可以帮你具体分析是哪一类原因。