CentOS Apache2出现404错误,可按以下步骤排查解决:
sudo systemctl status httpd
,未启动则执行 sudo systemctl start httpd
。/etc/httpd/conf/httpd.conf
或虚拟主机配置文件(如 /etc/httpd/conf.d/your-site.conf
)中的 DocumentRoot
路径是否正确,指向网站实际目录。sudo apachectl configtest
检查配置语法是否有误。apache
)对网站目录及文件有访问权限,执行:sudo chown -R apache:apache /var/www/html
sudo chmod -R 755 /var/www/html
```。
sudo setenforce 0
若问题解决,需调整SELinux策略或永久禁用(不推荐)。sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
```。
sudo tail -f /var/log/httpd/error_log
获取详细错误信息,定位具体问题(如文件不存在、权限不足等)。.htaccess
或URL重写,确保mod_rewrite
模块已启用,且配置正确(如AllowOverride All
)。完成修改后,重启Apache服务:sudo systemctl restart httpd
。若问题仍未解决,根据错误日志进一步排查。