在 CentOS 上,Apache(通常叫 httpd)的配置文件位置和结构如下:
CentOS 7 / 8 / Stream
/etc/httpd/conf/httpd.conf
这是 Apache 的主配置文件,几乎所有全局设置都在这里(端口、根目录、模块等)。
/etc/httpd/conf.d/
.conf 结尾的文件例如:
/etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/example
<Directory /var/www/html/example>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
默认:
/var/www/html
# 启动
systemctl start httpd
# 开机自启
systemctl enable httpd
# 重启
systemctl restart httpd
# 查看状态
systemctl status httpd
# 检查配置是否正确
httpd -t
/var/log/httpd/access_log
/var/log/httpd/error_log
如果页面 403:
# 允许 httpd 访问目录
chcon -R -t httpd_sys_content_t /var/www/html
# 或临时关闭
setenforce 0
如果你是要配 HTTPS / PHP / 多域名 / 反向代理,告诉我具体需求,我可以直接给你完整配置。