Apache 日志不更新通常不是单一原因,常见原因和排查思路如下(按出现频率排序):
如果你使用了 logrotate,但配置中没有让 Apache 重新打开日志文件:
access.log.1)✅ 排查:
ls -l /var/log/apache2/
lsof | grep access.log
✅ 解决:
systemctl restart apache2
# 或
service apache2 restart
或 logrotate 配置中必须有:
postrotate
systemctl reload apache2
endscript
如果日志级别被设为 error 或 warn,访问日志可能看起来“没更新”。
✅ 检查:
LogLevel warn
✅ 建议:
LogLevel info
请求可能:
✅ 排查:
apache2ctl -S
确认:
日志写到了你没注意的地方。
✅ 检查:
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
✅ 搜索所有日志配置:
grep -R "CustomLog\|ErrorLog" /etc/apache2/
特别是静态资源:
✅ 验证:
curl -I http://your-domain/
或:
curl http://your-domain/?nocache=1
请求可能被:
✅ 检查:
ss -lntp | grep apache
Apache 不会报错,但日志写不进去。
✅ 检查:
df -h
df -i
日志目录可能被限制写入。
✅ 检查:
getenforce
✅ 临时验证:
setenforce 0
df -h 看磁盘apache2ctl -S 看虚拟主机grep CustomLog /etc/apache2/ -Rlsof | grep access.logcurl 发请求测试systemctl restart apache2你可以直接贴出:
<VirtualHost> 配置我可以帮你精确判断是哪一类问题。