如何在转到服务器根目录时禁用apache2的目录索引?

Luc*_*lli 15 apache security indexing webserver

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

小智 34

编辑通常在目录上的apache2配置文件:"/ etc/apache2/httpd .conf".

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

 <Directory /var/www>
   Options -Indexes
   AllowOverride All
   Order allow,deny
   Allow from all
 </Directory>
Run Code Online (Sandbox Code Playgroud)

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

  • 在Ubuntu(和,据说,Debian)那是`/ etc/apache2/apache2.conf`.由于Apache结构因发行版而异,我建议使用`grep -r"Directory/var/www"/ etc/apache2`进行搜索. (3认同)

AJ.*_*AJ. 19

通常这样做:

Options -Indexes
Run Code Online (Sandbox Code Playgroud)

减号意味着"不"......

  • @AJ 我对此很新手,你能详细说明一下吗?我不知道该把它放在哪里 ^^ 我在 apache2.conf 中尝试过,但似乎不起作用 (3认同)
  • 这已经是差不多8年前的事了。 (2认同)

NoB*_*ugs 10

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


kjo*_*nes 7

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

sudo a2dismod --force autoindex
Run Code Online (Sandbox Code Playgroud)

使用--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
Run Code Online (Sandbox Code Playgroud)

这是以下文档mod_autoindex


小智 6

须藤纳米 /etc/apache2/apache2.conf

<Directory /var/www/>在文件中找到此部分

向索引添加减号(拒绝)

为 FollowSymLinks 添加一个加号

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

在 Raspbian 中工作

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