CentOS 上 Apache(httpd)配置失败的原因很多,通常可以从下面几类排查。你可以对照看看属于哪一种:
systemctl restart httpd
Job for httpd.service failed.
httpd -t
# 或
apachectl configtest
> 或 </VirtualHost>DocumentRoot 路径不存在Listen 80ss -lntp | grep :80
配置正确,但访问 403 / 打不开
getenforce
# 临时
setenforce 0
# 永久(不推荐生产)
vi /etc/selinux/config
SELINUX=disabled
或修改目录上下文:
chcon -R -t httpd_sys_content_t /var/www/html
firewall-cmd --list-all
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
CentOS 默认:
apache
ps aux | grep httpd
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
php 但没装mod_ssl 没开就用 httpshttpd -M
CentOS 正确路径:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
⚠ 不要直接改 /usr/ 下的文件
journalctl -xe
cat /var/log/httpd/error_log
你可以把具体报错信息或配置文件内容发出来,我可以直接帮你定位是哪一步错了。