【问题标题】:How to enable a directory listing in Apache web server [closed]如何在 Apache Web 服务器中启用目录列表 [关闭]
【发布时间】:2017-01-07 10:25:15
【问题描述】:

我无法在我的 Apache Web 服务器中启用目录列表。我尝试了各种发布的解决方案,但它不起作用。我刚刚安装了 httpd 2.4.6 并使用 /etc/httpd/conf.d/ssl.conf 目录下的 ssl.conf 启用了 HTTPS,并尝试访问 @987654321 @,但这没有列出目录。这些是文件 ssl.conf 中的配置:

DocumentRoot "/home/userx/Downloads/"
ServerName server.example.com:443

下面是它在 VirtualHost 元素下的 ssl.conf 中的内容。文件和第一个 Directory 元素在我安装时已经存在,我只是为“/home/userx/Downloads”添加了 Directory。当我访问 URL https://server.example.com/ 时,我想浏览 /home/userx/Downloads 的内容。我在这里错过了什么?

<Files ~ "\.(cgi|shtml|phtml|php3?)$">
    SSLOptions +StdEnvVars
</Files>
<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>
<Directory "/home/userx/Downloads">
  Options +Indexes
  AllowOverride all
</Directory>

【问题讨论】:

    标签: apache httpd.conf


    【解决方案1】:

    查看您是否能够访问/列出“/icons/”目录。这对于测试 Apache 中“目录”的行为很有用。

    例如:您的 httpd.conf 文件中可能默认具有以下配置。所以点击 URL IP:Port/icons/ 看看它是否列出了图标。您也可以尝试将“目录/文件夹”放在“var/www/icons”中。

    Alias /icons/ "/var/www/icons/"
    
    <Directory "/var/www/icons">
        Options Indexes MultiViews
        AllowOverride None
        Require all granted
    </Directory>
    

    如果它确实有效,那么您可以使用 '' 配置交叉检查或修改您的自定义目录配置。

    【讨论】:

    【解决方案2】:

    根据 Apache 文档 found here,需要在站点 .conf 文件中指定 DirectoryIndex 指令(通常在 Linux 上的 /etc/apache2/sites-available 中找到)。

    引用文档,内容如下:

    如果DirectoryIndex 指令中没有文件可以位于 目录,然后 mod_autoindex 可以生成目录的列表 内容。这是使用Options 指令打开和关闭的。为了 例如,要打开特定目录的目录列表,您 可以使用:

    <Directory /usr/local/apache2/htdocs/listme>
      Options +Indexes
    </Directory>
    

    为了防止目录列表(例如出于安全目的), 您应该从每个 Options 指令中删除 Indexes 关键字 你的配置文件。或者为了防止他们只为一个 目录,你可以使用:

    <Directory /usr/local/apache2/htdocs/dontlistme>
      Options -Indexes
    </Directory>
    

    【讨论】:

    • 非常有用的答案.. 终于成功了!
    【解决方案3】:

    试试这个。

    <Directory "/home/userx/Downloads">
      Options +Indexes
      AllowOverride all
      Order allow,deny 
      Allow from all 
      Require all granted
    </Directory>
    

    如果这不起作用,您可能在某个地方有“拒绝索引”覆盖了您的配置。

    【讨论】:

    • 更改为您的建议并重新启动服务器后仍然无法正常工作。日志显示:[Tue Aug 30 18:40:46.492983 2016] [authz_core:debug] [pid 20665] mod_authz_core.c(809): [client 171.71.229.25:59061] AH01626: Require all denied: denied [ 2016 年 8 月 30 日星期二 18:40:46.493000] [authz_core:debug] [pid 20665] mod_authz_core.c(809): [client 171.71.229.25:59061] AH01626: 的授权结果: 拒绝
    • 啊,好吧。我忘记了 Apache 2.4 需要全部授权。我会更新答案。
    • 没有帮助的事件。可能是我遇到了一些基本问题,因为使用 DocumentRoot“/home/userx/Downloads/”,我在其中创建了一个测试目录,并在该测试目录中创建了一个 index.html 文件,但也不允许访问 server.example.com/test/index.html。 [pid 21402] mod_authz_core.c(809): [client 171.71.229.25:59498] AH01626: 的授权结果: 已授予 [Tue Aug 30 18:55:38.108746 2016] [core:error] [pid 21402] ( 13)权限被拒绝:[client 171.71.229.25:59498] AH00132:文件权限拒绝服务器访问:/home/sburnwal/Downloads/test/index.html
    • 为了测试,将 index.html chmod 为 775。之后是否允许?
    • 我对 index.html 做了 chmod 755 但还没有运气。我还确保 chmod 755 到 / dir
    【解决方案4】:

    我通过从 Apache 启用 mod_autoindex 解决了这个问题。默认禁用。

    sudo a2enmod autoindex
    

    【讨论】:

    • 你是如何启用它的?
    • sudo a2enmod autoindex
    • a2enmod : 找不到命令
    • @Kokodoko,那是因为 a2enmod 是一个 debian 的东西。
    【解决方案5】:

    在我将 conf 文件中的 Options -Index 更改为 Options +Index 后,我删除了欢迎页面并重新启动了服务。

    $ sudo rm -f /etc/httpd/conf.d/welcome.conf
    $ sudo service httpd restart
    

    之后我可以看到目录列表。

    【讨论】:

      【解决方案6】:

      这个解决了我的问题,即SELinux 设置:

      chcon -R -t httpd_sys_content_t /home/*
      

      【讨论】:

      • 这正是我的问题。对于其他人,将 /home/* 更改为您的内容路径(在我的情况下为 /var/repo/)。由于您使用的是 -R,因此 * 可能不是必需的。
      【解决方案7】:

      我必须禁用SELinux 模块才能使其工作。注意:需要重启系统才能使 SELinux 生效。

      【讨论】:

        【解决方案8】:

        一种方法是创建指向您想要在 /var/www/html/ 目录中列出的任何目录的软链接。

        sudo ln -s /home/ /var/www/html/
        

        牢记安全性。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-08-19
          • 2020-10-16
          • 1970-01-01
          • 1970-01-01
          • 2018-05-09
          • 1970-01-01
          • 1970-01-01
          • 2013-05-06
          相关资源
          最近更新 更多