在 Ubuntu 上查看和检查 Apache 配置,通常可以按下面几个步骤来做:
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/cat /etc/apache2/apache2.conf
ls /etc/apache2/sites-enabled/
cat /etc/apache2/sites-enabled/000-default.conf
cat /etc/apache2/ports.conf
在修改配置后,一定要先测试:
sudo apache2ctl configtest
或:
sudo apache2ctl -t
✅ 输出 Syntax OK 表示配置正确
systemctl status apache2
启动 / 重启 / 停止:
sudo systemctl start apache2
sudo systemctl restart apache2
sudo systemctl stop apache2
查看运行中的配置(包括所有 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 配置),可以告诉我,我可以给你更针对性的命令。