当我访问我的网站时,会显示所有文件的索引,当我选择特定页面时,HTML无法访问文件中的图像。如何使Apache2自动启动/var/www/home.html而不是/var/www?
您可以在虚拟主机上下文中使用 DirectoryIndex 指令。
来自 Apache 网站
DirectoryIndex 指令设置了当客户端请求目录索引时要查找的资源列表, 客户端通过在目录名称末尾指定 / 来请求目录索引。
以下是示例:
<virtualhost *:80>
ServerName domain.com
ServerAlias www.domain.com
# Index file and Document Root (where the public files are located)
DirectoryIndex home.html index.html
DocumentRoot /var/www
</virtualhost>
DirectoryIndex
指令放置在sites-available/default
配置文件的virtualhost
标签内并不起作用。相反,按照http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex中提到的方法,在apache2.conf
文件的Directory
标签内放置DirectoryIndex
指令恰好实现了我们想要的效果。