CentOS 上 Apache 日志为空,通常不是“没访问”,而是日志路径、权限、配置或轮转出了问题。下面按常见原因逐一排查:
CentOS 下 Apache(httpd)默认日志位置:
/var/log/httpd/access_log
/var/log/httpd/error_log
但如果你用了:
日志可能写到了别的地方。
查看实际配置:
grep -R "CustomLog" /etc/httpd/
grep -R "ErrorLog" /etc/httpd/
systemctl status httpd
ps aux | grep httpd
如果没运行,当然不会有日志。
Apache 一般以 apache 用户运行:
ps aux | grep httpd
检查日志目录权限:
ls -ld /var/log/httpd
ls -l /var/log/httpd
正确示例:
drwx------ apache apache /var/log/httpd
如果权限不对:
chown -R apache:apache /var/log/httpd
chmod 700 /var/log/httpd
systemctl restart httpd
即使权限正确,SELinux 也可能阻止写入。
检查:
getenforce
如果为 Enforcing,看审计日志:
tail /var/log/audit/audit.log | grep httpd
临时验证:
setenforce 0
如果日志立刻有内容,说明是 SELinux 问题。
修复方式(推荐):
restorecon -Rv /var/log/httpd
检查是否有轮转后未重建:
ls -l /var/log/httpd/
cat /etc/logrotate.d/httpd
如果 access_log 大小为 0 但存在旧文件:
systemctl restart httpd
确认端口通:
curl http://localhost
curl http://服务器IP
防火墙:
firewall-cmd --list-all
如果你是用:
httpd -k start
或某些最小化安装,日志可能进了:
journalctl -u httpd
systemctl status httpd
ls -l /var/log/httpd
getenforce
grep -R CustomLog /etc/httpd
curl http://localhost
journalctl -u httpd -n 20
如果你愿意,可以把下面信息发我,我能直接判断:
cat /etc/redhat-release)httpd -S 输出我可以帮你精确定位。