【问题标题】:Directory Listing at domain level (Apache)域级别的目录列表 (Apache)
【发布时间】:2016-01-08 05:59:45
【问题描述】:

我在 Apache 2.4 Web 服务器(AWS EC2 主机)上有一个子域,设置了索引 - 但它没有在顶层显示索引:仅在子目录中。如果顶层 (http://stuff.example.com) 没有 DirectoryIndex 文件 (index.html),它只会显示 Amazon Linux AMI 测试页面。如果我在顶层有一个 index.html 文件,它会正常显示。

我试图找到没有为域页面显示索引的文档,但找不到。因此我必须在这个基本配置(httpd.conf)中遗漏一些东西:

<Directory "/data/stuff">
    AllowOverride Indexes AuthConfig
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName stuff.example.com
    DocumentRoot /data/stuff
    Options +Indexes +FollowSymLinks
</VirtualHost>

【问题讨论】:

  • “Amazon Linux AMI 测试页面”可能是通过DirectoryIndex 配置的,只是名称与index.htm(l) 不同,因此它仅在您不提供索引时充当备用自己归档。您是否尝试过在Directory 指令中自己指定DirectoryIndex? (DirectoryIndex 是添加到现有配置还是覆盖它,取决于之前是否已在同一上下文中指定。)
  • 亲爱的@CBroe——“测试页面”没有配置DirectoryIndex,而是来自/var/www/noindex/index.html,这不是httpd.conf中任何地方的参数&显然内置在默认配置中:即使我在Directory 指令中指定DirectoryIndex disabled,它仍然会产生该测试页​​。我还尝试将 Options IndexesVirtualHost 指令移动到 Directory 指令(没有变化)。您认为我应该尝试一些具体的措辞吗?
  • 持有它;我在/etc/httpd/conf.d/welcome.confconf.d 中的其他文件中看到了更多配置——这就是定义“测试”(错误)页面的地方。将检查其中是否有需要覆盖的指令....
  • 事实上,这就是解决方案。 welcome.conf&lt;LocationMatch "^/+$"&gt; 中定义了 Options -Indexes,cmets 说它应该匹配“根 URL”——而且,我们已经看到,它也匹配任何裸子域。注释掉该行会将目录列表恢复到我的子域的根 URL。 @CBroe,如果您想总结解决方案,我很乐意为您服务,否则我会这样做...谢谢/r
  • 那么你看到的欢迎页面实际上被定义为 403 Forbidden 的 ErrorDocument 呢? // 很高兴让你写下你自己发现的东西,就像“self-answer” 之类的。

标签: apache .htaccess amazon-ec2 httpd.conf


【解决方案1】:

在 Apache 2.4 的 AWS EC2 配置中(至少),还有一个额外的配置文件/etc/httpd/conf.d/welcome.conf

<LocationMatch "^/+$">
    Options -Indexes
    ErrorDocument 403 /.noindex.html
</LocationMatch>

<Directory /var/www/noindex>
    AllowOverride None
    Require all granted
</Directory>

Alias /.noindex.html /var/www/noindex/index.html

这不仅揭示了 Amazon Linux AMI 测试页面的性质,还解释了为什么该页面会覆盖子域根 URL 的目录列表:因为它与正则表达式匹配在LocationMatch

如果网络管理员尚未添加索引页面,此代码旨在向网站访问者显示一些有用的信息......但它也具有抑制任何子域的根 URL 的目录列表的副作用。一种解决方案是注释掉或删除 /etc/httpd/conf.d/welcome.conf 中的 Options -Indexes 指令。

【讨论】:

  • ...如果我必须完全减少“副作用”,另一种解决方案是在httpd.conf 中添加一个覆盖的LocationMatch 指令,匹配子域并包含Options +Indexes
【解决方案2】:

您可以设置自己的 DirectoryIndex,它将覆盖默认值。

<VirtualHost *:80>
    ServerName stuff.example.com
    DocumentRoot /data/stuff
    DirectoryIndex index.php
    Options +Indexes +FollowSymLinks
</VirtualHost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 2011-05-30
    • 2018-03-03
    相关资源
    最近更新 更多