默认首页由 directoryindex 指令设置,它定义目录访问时按序匹配的首页文件列表,如 directoryindex index.html index.htm index.php;需确保文件存在、可读,目录权限允许访问,并重启 apache 生效。

在 Apache 的主配置文件 httpd.conf 中,设置默认首页靠的是 DirectoryIndex 指令,不是 DocumentRoot 或其他参数。
DirectoryIndex 是核心配置项
它定义了当用户访问一个目录(比如 https://example.com/)时,Apache 自动查找并返回的文件名列表。服务器按顺序匹配,找到第一个存在的文件就直接返回。
Apache Superset 是一个广泛采用的开源 BI 平台,用于 SQL 探索、图表构建和仪表板交付。当代理需要查询仓库数据、组装仪表板或使用成熟的分析界面解释指标而不是临时笔记本代码时,此技能非常有用。
- 典型写法:
DirectoryIndex index.html index.htm index.php - 只要
index.html存在且可读,就会作为首页加载;如果不存在,才尝试index.htm,依此类推 - 你可以把最常用的首页文件放在最前面,比如想优先用
home.html,就写成:DirectoryIndex home.html index.html index.php
修改位置和注意事项
这个指令通常出现在 httpd.conf 的“主服务器配置”段,也可能在虚拟主机块或 .htaccess 文件里。查找时注意:
- 用文本编辑器打开
httpd.conf(Linux 常在/etc/httpd/conf/httpd.conf或/etc/apache2/apache2.conf;Windows 多在Apache/conf/目录下) - 搜索关键词
DirectoryIndex,确认该行未被注释(即开头没有#) - 确保文件名之间用空格分隔,不要加逗号或引号
- 大小写敏感:Linux 系统下
Index.html和index.html是不同文件
配套检查不能少
光改 DirectoryIndex 不够,还得确认:
-
DocumentRoot指向的目录里,确实存在你设的首页文件(如index.html) - 该文件权限为可读(例如 Linux 下运行
chmod 644 index.html) - 对应目录的
<directory></directory>块中允许索引访问,比如包含Require all granted或旧版的Allow from all - 修改后必须重启 Apache 生效:
sudo systemctl restart httpd(CentOS/RHEL)或sudo systemctl restart apache2(Ubuntu/Debian)










