温馨提示×

如何查看linux apache配置

小樊
48
2026-10-29 00:54:11
栏目: 智能运维

在 Linux 下查看 Apache 配置,通常可以从配置文件位置、配置内容、运行参数几个层面来做。下面按常见场景说明(以 Apache 2 / httpd 为主)。


一、查看 Apache 是否安装及版本

apachectl -v
# 或
httpd -v

若提示命令不存在,可能未安装或路径不在 PATH 中。


二、查找 Apache 配置文件位置

1. 查看编译时默认配置路径

apachectl -V
# 或
httpd -V

重点看这几项:

  • SERVER_CONFIG_FILE
  • HTTPD_ROOT

例如:

HTTPD_ROOT="/etc/httpd"
SERVER_CONFIG_FILE="conf/httpd.conf"

2. 常见默认路径(发行版差异)

CentOS / RHEL / Rocky / Alma

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

Ubuntu / Debian

/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/
/etc/apache2/mods-enabled/
/etc/apache2/conf-enabled/

三、查看当前生效的主配置

1. 直接查看主配置文件

cat /etc/httpd/conf/httpd.conf
# 或
cat /etc/apache2/apache2.conf

2. 查看包含的其他配置文件

Apache 常通过 Include 引入其他配置:

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

Ubuntu 可用:

apache2ctl -S

四、查看当前运行中的配置(推荐)

1. 查看虚拟主机配置

apachectl -S
# 或
httpd -S

会显示:

  • 监听端口
  • 虚拟主机
  • 配置文件位置

2. 查看模块加载情况

apachectl -M

输出已加载模块(如 rewrite_module)。


五、查看运行参数(进程级)

1. 查看 Apache 进程启动参数

ps aux | grep httpd
# 或
ps aux | grep apache2

2. 查看监听端口

ss -lntp | grep httpd
# 或
netstat -lntp | grep httpd

六、测试配置文件是否正确

修改配置后,务必先测试:

apachectl configtest
# 或
httpd -t

输出 Syntax OK 表示无误。


七、快速排查思路总结

  1. 不确定配置在哪 → apachectl -V
  2. 不确定哪条规则生效 → apachectl -S
  3. 不确定模块是否开 → apachectl -M
  4. 改完配置 → configtest → restart

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

  • 使用的 Linux 发行版
  • Apache 是 httpd 还是 apache2
  • 想查的是 虚拟主机 / 重写规则 / 端口 / 性能参数

我可以直接给你对应的具体命令。

0 踩