温馨提示×

如何查ubuntu apache配置

小樊
47
2026-09-29 07:17:33
栏目: 智能运维

在 Ubuntu 上查看和检查 Apache 配置,通常可以按下面几个步骤来做:


一、Apache 配置文件位置(Ubuntu)

Ubuntu 中 Apache 一般使用 Apache2,主要配置目录是:

/etc/apache2/

常见文件和目录:

  • /etc/apache2/apache2.conf:主配置文件
  • /etc/apache2/ports.conf:端口配置(如 80、443)
  • /etc/apache2/sites-available/:可用站点配置
  • /etc/apache2/sites-enabled/:已启用站点(符号链接)
  • /etc/apache2/mods-available/:可用模块
  • /etc/apache2/mods-enabled/:已启用模块
  • /etc/apache2/conf-available/
  • /etc/apache2/conf-enabled/

二、查看当前 Apache 配置

1️⃣ 查看主配置

cat /etc/apache2/apache2.conf

2️⃣ 查看已启用的网站配置

ls /etc/apache2/sites-enabled/
cat /etc/apache2/sites-enabled/000-default.conf

3️⃣ 查看监听端口

cat /etc/apache2/ports.conf

三、检查 Apache 配置是否正确

在修改配置后,一定要先测试:

sudo apache2ctl configtest

或:

sudo apache2ctl -t

✅ 输出 Syntax OK 表示配置正确


四、查看 Apache 当前运行状态

systemctl status apache2

启动 / 重启 / 停止:

sudo systemctl start apache2
sudo systemctl restart apache2
sudo systemctl stop apache2

五、查看 Apache 实际生效的配置(高级)

查看运行中的配置(包括所有 Include):

apache2ctl -S

或:

apache2ctl -t -D DUMP_VHOSTS

查看模块加载情况:

apache2ctl -M

六、查看错误日志(排查问题很有用)

sudo tail -f /var/log/apache2/error.log

访问日志:

sudo tail -f /var/log/apache2/access.log

七、示例:查看某个网站用的配置

sudo apache2ctl -t -D DUMP_VHOSTS

输出示例:

*:80   is a NameVirtualHost
         default server  example.com (/etc/apache2/sites-enabled/example.conf:1)

如果你有 具体需求(比如:查 HTTPS、查 rewrite、查 403/404 原因、查 PHP 配置),可以告诉我,我可以给你更针对性的命令。

0 踩