【问题标题】:How to disable directory indexing from apache2 when going to the server's root?转到服务器的根目录时如何从 apache2 禁用目录索引?
【发布时间】:2011-09-14 02:11:43
【问题描述】:

当我进入 apache2 服务器上的根目录时,我需要禁用该索引,有什么提示吗?

【问题讨论】:

    标签: security apache indexing webserver


    【解决方案1】:

    通常这样做:

    Options -Indexes
    

    减号表示“不”...

    【讨论】:

    • @AJ 我是这方面的新手,你能详细说明一下吗?我不知道把那个放在哪里^^我在apache2.conf上试过,但似乎没有用
    • 这差不多是 8 年前的事了。
    【解决方案2】:

    如果您只想保护一个目录不被查看内容,您也可以添加一个 index.html 或 index.php,只要有人浏览该目录就会显示该目录。

    【讨论】:

      【解决方案3】:

      编辑您的 apache2 配置文件,该文件通常位于目录:“/etc/apache2/httpd.conf”。

      如果您已经对默认 Web 服务器目录 (/var/www) 进行了一些配置,请添加以下内容或进行编辑:

       <Directory /var/www>
         Options -Indexes
         AllowOverride All
         Order allow,deny
         Allow from all
       </Directory>
      

      这将禁用对所有公共目录的索引。

      【讨论】:

      • 在 Ubuntu(也应该是 Debian)中是 /etc/apache2/apache2.conf。由于 Apache 的结构因发行版而异,我建议使用 grep -r "Directory /var/www" /etc/apache2 搜索它。
      【解决方案4】:

      确保您还将 -Indexes 添加到启用站点(或在我的情况下为站点可用)目录中的配置文件中,它们通常位于“/etc/apache2/”目录中。

      【讨论】:

        【解决方案5】:

        sudo nano /etc/apache2/apache2.conf

        在文件中找到此部分&lt;Directory /var/www/&gt;

        给索引加一个减号(拒绝)

        为 FollowSymLinks 添加一个加号

        结果: <Directory /var/www/> Options -Indexes +FollowSymLinks AllowOverride None Require all granted </Directory>

        在 Raspbian 中工作

        您将收到消息:“您无权访问此服务器上的“目录”。”

        【讨论】:

        • 仅供参考:通过禁用索引,您会收到消息“您无权访问此资源。”,403 错误。
        【解决方案6】:

        如果您的发行版中有 a2dismod 实用程序,如果您根本不需要目录索引,则可以完全删除该模块:

        sudo a2dismod --force autoindex
        

        使用--force-f 标志来避免以下警告:

        WARNING: The following essential module will be disabled.                                                                                                                   
        This might result in unexpected behavior and should NOT be done                                                                                                             
        unless you know exactly what you are doing!                                                                                                                                 
         autoindex                                                                                                                                                                  
                                                                                                                                                                                    
        To continue type in the phrase 'Yes, do as I say!' or retry by passing '-f': Yes, do as I say!                                                                              
        Module autoindex disabled.                                                                                                                                                  
        To activate the new configuration, you need to run:                                                                                                                         
          systemctl restart apache2
        

        这是mod_autoindex的文档

        【讨论】:

        • 仅供参考:通过禁用自动索引,您会收到消息“在此服务器上找不到请求的 URL。”,404 错误。
        猜你喜欢
        • 2015-09-02
        • 1970-01-01
        • 1970-01-01
        • 2015-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-23
        • 2013-07-20
        相关资源
        最近更新 更多