在 CentOS 上,Apache(通常是 httpd)的日志位置取决于安装方式和版本,但绝大多数情况下日志在 /var/log/httpd/ 目录下。
下面按常见场景说明。
/var/log/httpd/access_log # 访问日志
/var/log/httpd/error_log # 错误日志
如果使用了 虚拟主机(VirtualHost),可能还有:
/var/log/httpd/域名-access_log
/var/log/httpd/域名-error_log
tail -f /var/log/httpd/error_log
tail -f /var/log/httpd/access_log
tail -n 100 -f /var/log/httpd/error_log
grep "404" /var/log/httpd/access_log
grep "PHP" /var/log/httpd/error_log
ls -lh /var/log/httpd/
rpm -qa | grep httpd
# 或
which httpd
grep -R "ErrorLog" /etc/httpd/
grep -R "CustomLog" /etc/httpd/
常见配置文件:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
systemctl status httpd
systemctl start httpd
systemctl enable httpd
CentOS 使用 logrotate:
ls /var/log/httpd/
你可能会看到:
access_log-20260101.gz
error_log-20260101.gz
查看历史日志:
zcat /var/log/httpd/error_log-20260101.gz | less
如果 Apache 正常运行但 日志为空,可能是 SELinux 限制:
getenforce
临时关闭测试:
setenforce 0
(生产环境建议正确配置 SELinux,而非直接关闭)
如果你愿意,可以告诉我:
yum 安装我可以给你更精确的命令。