温馨提示×

如何查centos apache配置

小樊
38
2026-09-06 02:27:30
栏目: 智能运维

在 CentOS 上查看 Apache(通常是 httpd)的配置,可以从以下几个方面入手:


一、确认 Apache 是否已安装及服务名

CentOS 上 Apache 一般叫 httpd

rpm -qa | grep httpd
# 或
which httpd

查看服务状态:

systemctl status httpd

二、Apache 主配置文件位置

CentOS 7/8/Stream 常见路径:

/etc/httpd/conf/httpd.conf        # 主配置文件
/etc/httpd/conf.d/                # 额外配置文件(如 ssl.conf、virtual host)

查看主配置:

cat /etc/httpd/conf/httpd.conf

三、快速查看关键配置项

可用 grep 过滤:

grep -i "ServerRoot" /etc/httpd/conf/httpd.conf
grep -i "DocumentRoot" /etc/httpd/conf/httpd.conf
grep -i "Listen" /etc/httpd/conf/httpd.conf

四、查看所有生效的配置(含 conf.d)

Apache 启动时会加载:

  • 主配置
  • Includeconf.d/*.conf

查看被包含的文件:

grep -i "Include" /etc/httpd/conf/httpd.conf

列出所有配置:

ls -l /etc/httpd/conf.d/

五、验证配置文件是否正确

修改配置后一定要测试:

httpd -t
# 或
apachectl configtest

输出 Syntax OK 表示正常。


六、查看实际运行中的配置

如果 Apache 已启动,可查看编译参数和运行信息:

httpd -V

查看模块:

httpd -M

七、查看虚拟主机配置

grep -i "VirtualHost" -R /etc/httpd/

或查看:

cat /etc/httpd/conf.d/*.conf

八、查看日志(辅助排查配置问题)

/var/log/httpd/access_log
/var/log/httpd/error_log

实时查看:

tail -f /var/log/httpd/error_log

如果你愿意,可以告诉我:

  • CentOS 版本(6 / 7 / 8 / Stream)
  • 想查的是 虚拟主机 / SSL / 端口 / 权限 哪一类

我可以给你更精准的命令。

0