在 CentOS 上排查 Apache(通常是 httpd)错误,一般按下面几个方向来查:
/var/log/httpd/error_log
查看最新错误:
tail -f /var/log/httpd/error_log
或查看最近 100 行:
tail -n 100 /var/log/httpd/error_log
如果你用了虚拟主机,可能在:
/var/log/httpd/你的域名-error_log
httpd -t
或
apachectl configtest
输出:
Syntax OK → 配置没问题service httpd status
service httpd restart
systemctl status httpd
systemctl restart httpd
如果启动失败,错误通常会显示在:
journalctl -xe
或
systemctl status httpd -l
/var/log/messages
/var/log/secure
SELinux 导致访问被拒时:
tail -f /var/log/audit/audit.log
临时排查 SELinux:
setenforce 0
(仅测试用,不建议长期关闭)
编辑配置文件:
vi /etc/httpd/conf/httpd.conf
确保:
LogLevel warn
可临时改为:
LogLevel debug
重启:
systemctl restart httpd
| 现象 | 可能原因 |
|---|---|
| 403 Forbidden | 文件权限 / SELinux |
| 404 Not Found | DocumentRoot 配错 |
| 500 Internal Error | PHP 错误 / .htaccess |
| 无法启动 | 端口被占用 / 配置错误 |
如果你能贴出 具体的报错内容(比如 error_log 里的一段),我可以帮你精准分析。