将默认页面更改为Apache2 Ubuntu

8
当我访问我的网站时,会显示所有文件的索引,当我选择特定页面时,HTML无法访问文件中的图像。如何使Apache2自动启动/var/www/home.html而不是/var/www?
2个回答

11

您可以在虚拟主机上下文中使用 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>

以上是针对目录特定范围配置的设置。对于Apache环境范围配置,请使用下面网址中的指示,并在dir.conf中进行更改。https://dev59.com/2nE95IYBdhLWcg3wRLst - Dung
完美答案。如果您正在使用WordPress,请仅添加DirectoryIndex index.php并重新启动Apache。 - error2007s

3
在Apache2中,将DirectoryIndex指令放置在sites-available/default配置文件的virtualhost标签内并不起作用。相反,按照http://httpd.apache.org/docs/2.2/mod/mod_dir.html#directoryindex中提到的方法,在apache2.conf文件的Directory标签内放置DirectoryIndex指令恰好实现了我们想要的效果。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接