排查CentOS Apache错误日志可按以下步骤进行:
-
查看错误日志
- 日志路径:
/var/log/httpd/error_log。 - 实时查看:
sudo tail -f /var/log/httpd/error_log。 - 搜索关键字:
grep "ERROR" /var/log/httpd/error_log。
- 日志路径:
-
检查配置文件语法
- 执行命令:
sudo apachectl configtest,修复语法错误。
- 执行命令:
-
排查端口占用
- 检查80/443端口:
sudo netstat -tulnp | grep ':80\|:443',终止冲突进程或修改Apache端口。
- 检查80/443端口:
-
验证文件权限
- 确保Apache用户(通常为
apache)有权访问文件/目录:
sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html。
- 确保Apache用户(通常为
-
处理SELinux限制
- 临时关闭SELinux:
sudo setenforce 0,排查后恢复sudo setenforce 1。
- 临时关闭SELinux:
-
检查防火墙规则
- 开放HTTP/HTTPS流量:
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --reload。
- 开放HTTP/HTTPS流量:
-
分析日志内容
- 常见错误类型:
- 404 Not Found:资源路径错误或权限不足。
- 500 Internal Server Error:配置错误、模块加载失败或资源耗尽。
- 403 Forbidden:权限配置错误。
- 常见错误类型:
-
使用工具辅助分析
- 大型日志分析:
logrotate轮转日志,或通过ELK Stack、Splunk等工具可视化。
- 大型日志分析:
-
重启服务验证
- 修改配置后重启Apache:
sudo systemctl restart httpd。
- 修改配置后重启Apache:
若问题仍未解决,可参考Apache官方文档或社区论坛(如Stack Overflow)寻求帮助。