在 Ubuntu 上查看 Apache 配置,通常可以从配置文件位置、常用命令、虚拟主机配置几个方面入手。下面给你一套实用方法。
Ubuntu 使用 Debian 风格 的 Apache 配置结构:
/etc/apache2/apache2.conf
这是 Apache 的主配置入口。
/etc/apache2/ports.conf
查看 Apache 监听端口(如 80、443)。
/etc/apache2/mods-enabled/
/etc/apache2/mods-available/
/etc/apache2/sites-available/ # 可用站点
/etc/apache2/sites-enabled/ # 已启用站点(软链接)
/etc/apache2/conf-available/
/etc/apache2/conf-enabled/
systemctl status apache2
apache2 -v
或
apache2ctl -v
apache2ctl configtest
或
apache2 -t
apache2ctl -S
会显示:
ls /etc/apache2/sites-enabled/
查看某个站点内容:
cat /etc/apache2/sites-enabled/000-default.conf
apache2ctl -M
示例输出:
rewrite_module (shared)
ssl_module (shared)
/var/log/apache2/access.log
/var/log/apache2/error.log
实时查看错误:
tail -f /var/log/apache2/error.log
例如查找 DocumentRoot:
grep -R "DocumentRoot" /etc/apache2/
查找监听端口:
grep -R "Listen" /etc/apache2/
cat /etc/apache2/sites-enabled/000-default.conf
常见内容:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
</VirtualHost>
如果你愿意,可以告诉我:
我可以按你当前场景一步步帮你查。