【发布时间】:2011-09-14 02:11:43
【问题描述】:
当我进入 apache2 服务器上的根目录时,我需要禁用该索引,有什么提示吗?
【问题讨论】:
标签: security apache indexing webserver
当我进入 apache2 服务器上的根目录时,我需要禁用该索引,有什么提示吗?
【问题讨论】:
标签: security apache indexing webserver
通常这样做:
Options -Indexes
减号表示“不”...
【讨论】:
如果您只想保护一个目录不被查看内容,您也可以添加一个 index.html 或 index.php,只要有人浏览该目录就会显示该目录。
【讨论】:
编辑您的 apache2 配置文件,该文件通常位于目录:“/etc/apache2/httpd.conf”。
如果您已经对默认 Web 服务器目录 (/var/www) 进行了一些配置,请添加以下内容或进行编辑:
<Directory /var/www>
Options -Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
这将禁用对所有公共目录的索引。
【讨论】:
/etc/apache2/apache2.conf。由于 Apache 的结构因发行版而异,我建议使用 grep -r "Directory /var/www" /etc/apache2 搜索它。
确保您还将 -Indexes 添加到启用站点(或在我的情况下为站点可用)目录中的配置文件中,它们通常位于“/etc/apache2/”目录中。
【讨论】:
sudo nano /etc/apache2/apache2.conf
在文件中找到此部分<Directory /var/www/>
给索引加一个减号(拒绝)
为 FollowSymLinks 添加一个加号
结果:
<Directory /var/www/>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
在 Raspbian 中工作
您将收到消息:“您无权访问此服务器上的“目录”。”
【讨论】:
如果您的发行版中有 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的文档
【讨论】: