温馨提示×

apache日志报错centos怎么看

小樊
36
2026-10-09 01:02:58
栏目: 智能运维

在 CentOS 上查看 Apache 报错日志,通常按下面步骤来:


一、Apache 日志默认位置(CentOS)

CentOS 上 Apache 一般是 httpd:

/var/log/httpd/

常用日志文件:

  • 错误日志(重点看这个)
    /var/log/httpd/error_log
    
  • 访问日志
    /var/log/httpd/access_log
    

二、实时查看报错(最常用)

tail -f /var/log/httpd/error_log

或看最近 100 行:

tail -n 100 /var/log/httpd/error_log

三、搜索具体错误

比如找 Permission denied:

grep "Permission denied" /var/log/httpd/error_log

查看某个时间段的错误:

grep "2026" /var/log/httpd/error_log

四、Apache 没启动或配置错误

1️⃣ 检查 Apache 状态

systemctl status httpd

2️⃣ 测试配置文件

httpd -t

或

apachectl configtest

如果有错误,会直接告诉你哪一行配置有问题。


五、SELinux 常见坑(CentOS 特有)

如果日志里有:

Permission denied

但权限明明是对的,很可能是 SELinux 问题。

查看 SELinux 报错:

grep httpd /var/log/audit/audit.log

临时关闭测试(不推荐长期关):

setenforce 0

六、防火墙导致无法访问(不是报错但常见)

systemctl status firewalld

开放 80/443:

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

七、如果你用的是 PHP

PHP 错误也可能写在 Apache 日志里,或者:

/var/log/php-fpm/error.log

(如果是 PHP-FPM)


如果你愿意,可以把 具体的报错内容贴出来,我可以直接帮你判断是权限、配置、SELinux 还是代码问题。

0 踩