温馨提示×

centos apache在哪配置

小樊
53
2026-09-24 05:31:11
栏目: 智能运维

在 CentOS 上,Apache(通常叫 httpd)的配置文件位置如下:

1. 主配置文件

/etc/httpd/conf/httpd.conf

这是 Apache 的主配置文件,几乎所有全局配置都在这里。

2. 额外配置文件目录

/etc/httpd/conf.d/
  • 该目录下的 *.conf 文件会被自动加载
  • 常用于虚拟主机、模块配置(如 php.conf、ssl.conf)

3. 模块配置目录

/etc/httpd/conf.modules.d/
  • 用于加载 Apache 模块(.so)

4. 网站根目录

默认网站目录:

/var/www/html

可在 httpd.conf 中通过 DocumentRoot 修改。

5. 日志文件

/var/log/httpd/
  • access_log:访问日志
  • error_log:错误日志

常用管理命令

# 启动
systemctl start httpd

# 停止
systemctl stop httpd

# 重启
systemctl restart httpd

# 开机自启
systemctl enable httpd

# 检查配置是否正确
httpd -t

示例:配置虚拟主机

在 /etc/httpd/conf.d/ 下新建:

vim /etc/httpd/conf.d/example.conf

内容示例:

<VirtualHost *:80>
    ServerName www.example.com
    DocumentRoot /var/www/example
    <Directory /var/www/example>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

如果你用的是 CentOS 8 + nginx/apache 组合,或 CentOS Stream,配置位置基本一致。需要我帮你具体改某个配置也可以说。

0 踩