【问题标题】:How to show Directory Index in Apache 2.4 with custom Document Root如何使用自定义文档根在 Apache 2.4 中显示目录索引
【发布时间】:2014-02-16 06:18:06
【问题描述】:

我在 Ubuntu 13.10 的 Apache 2.4 中遇到问题。 我尝试将 Document Root 更改为 /home/fandi/public_html 一切正常。但我尝试在我的 public_html/ 中创建文件夹我收到这样的错误:

[Sat Jan 25 10:59:50.149441 2014] [autoindex:error] [pid 1093] [client 127.0.0.1:39901] AH01276: Cannot serve directory /home/fandi/public_html/report_php/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive

我必须创建文件index.htmlindex.php 和其他index.xxx 文件。

默认情况下它必须显示目录索引。 如何启用目录索引?

这是我的文件000-default.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/fandi/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/home/fandi/public_html">
        Options All
        AllowOverride All
        Require all granted
        Options Indexes FollowSymLinks
    </Directory>

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

请帮忙,谢谢之前^^

【问题讨论】:

标签: webserver apache2.4


【解决方案1】:

原来你需要在 Apache 2.4 中禁用 DirectoryIndex 才能获得自动索引。

DirectoryIndex disabled
Options Indexes

如果未禁用 DirectoryIndex,则自动索引不起作用,如果您使用 fastcgi/php-fpm,apache 会发送 403 Forbidden 或 404 File not found。

以下是相应的错误日志行(用于搜索):

[authz_core:error] client denied by server configuration:
[proxy_fcgi:error] Got error 'Primary script unknown\n'

【讨论】:

  • 会认为服务 /usr/share/apache2/icons/ 的失败会被某处的某个自动化测试套件发现。 alias.conf 默认启用 .../icons/ 但仍然有 [autoindex:error] ... AH01276: Cannot serve directory /usr/share/apache2/icons/谢谢!
  • 这对我来说是个问题。您必须先禁用 DirectoryIndex
  • 这对我没有任何作用。
  • 没有信息在哪里禁用 DirectoryIndex。
【解决方案2】:
Options All <--turn on all options
Options Indexes FollowSymLinks   <--- replace previously set options with these two

第二行是多余的,因为您已经打开了第一行的所有选项,并且由于这两个选项没有以+ 为前缀,因此它们实际上替换了整个选项列表启用集@987654323 @ 只有这两个单独的选项。

【讨论】:

  • 那么,我应该如何编辑?以前我只使用 Options All ,现在我尝试只使用 Options Indexes FollowSymLinks ,但它没有用。 :\
  • 对我没用。 Apache 2.4 突然让人头疼,我使用 apache 已经超过 10 年了。问题是,如果你用谷歌搜索它,你会得到过去 10 多年 2.2 的答案,这些都是错误的。
【解决方案3】:

我在使用 Centos 7.2 和 apache 2.4 时遇到了同样的问题。

在新安装中,问题很可能是由welcome.conf 在每个位置禁用选项索引引起的:

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

此文件在每次 Apache 升级时都会恢复,然后您应该注释或删除之前的行。

【讨论】:

  • 这是正确的解决方案,它也适用于其他 redhat 风格的发行版(即我的情况下的 Fedora)
【解决方案4】:

我设法让它工作

基本上,Apache2.4 似乎不会将设置从 DocumentRoot 转移到您的虚拟主机,除非虚拟主机是 DocumentRoot 的子文件夹,就像以前的版本一样。哪种是有道理的,但应该记录更改,但事实并非如此。

我的意思是,在您的 httpd.conf 中,您将拥有(这是一个 OS X):

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
    Options +Indexes +FollowSymLinks
    # etc
</Directory>

然后在你的 extra/httpd-vhosts.conf 中

<VirtualHost *:80>
    DocumentRoot "/pth/to/somewhere/completely/different"
    ServerName my-virtual-host.dev
    ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log"
    CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common
</VirtualHost>

VH 曾经继承所有设置 - 如果它不是子文件夹,则不再继承。所以你需要做的是复制并粘贴 VH 中的设置(或者如果你在同一个地方有很多 VH,你可以创建另一个 &lt;directory

<VirtualHost *:80>
    DocumentRoot "/pth/to/somewhere/completely/different"
    ServerName my-virtual-host.dev
    ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log"
    CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common
    <Directory "/pth/to/somewhere/completely/different">
        Options +Indexes
    </Directory>
</VirtualHost>

是 +Indexes 发挥了作用。

【讨论】:

  • 在 Debian 8.0 Jessie 的 Apache (2.4) 中,如果您使用自己的文档根为多个虚拟主机提供服务,则需要将 DocumentRoot /var/www 显式添加到您的 /etc/apache2/apache2.conf
【解决方案5】:

在日志中你可以发现一个错误

[Sun Dec 03 17:38:17.649269 2017] [autoindex:error] [pid 4806] [client ::1:57323] AH01276: 无法提供目录 /etc/httpd/conf/htdocs/: 没有匹配的 DirectoryIndex ( ) 找到,并且选项指令禁止服务器生成的目录索引

修复它:-

那么你必须删除 /etc/httpd/conf.d/welcome.conf 中的行

低于现有配置:-

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

通过以下配置解决:- 注释掉一行。

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

【讨论】:

    【解决方案6】:

    将此行添加到站点的 vhost.conf 文件中

    DirectoryIndex default.html

    你们都准备好了

    【讨论】:

      【解决方案7】:

      对于未来的人,如果您按照以上所有方法仍然存在问题,请尝试以下操作:

      httpd.conf(make sure belows are open):
      LoadModule alias_module modules/mod_alias.so
      LoadModule authz_core_module modules/mod_authz_core.so
      LoadModule authz_host_module modules/mod_authz_host.so
      LoadModule autoindex_module modules/mod_autoindex.so
      Include conf/extra/httpd-autoindex.conf
      

      额外/httpd-autoindex.conf:

      <Directory "change to your directory">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-16
        • 2018-10-22
        • 1970-01-01
        • 1970-01-01
        • 2015-01-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多