当你在浏览器输入地址:
http://localhost:8080/
如果你的文件根目录里有 index.html,浏览器就会显示 index.html的内容,如果没有 index.html,Apache将在浏览器显示文件根目录的目录列表,目录列表包括文件根目录下的文件和子目录。给网站造成安全风险。
同样当你输入一个虚拟目录的地址:
http://localhost:8080/My/
如果该虚拟目录下没有 index.html,浏览器也会显示该虚拟目录的目录结构,列出该虚拟目录下的文件和子目录。
我们可以通过修改Apache的配置文件,来禁止 Apache 显示目录结构列表。
打开httpd.conf ,来看一个目录配置:
<Directory "D:/WAMP/WWW">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
你只需要将上面红色代码中的 Indexes 去掉,就可以禁止Apache 显示该目录结构。用户就不会看到该目录下的文件和子目录列表了。
Indexes 的作用就是当该目录下没有 index.html 文件时,就显示目录结构。
现改为如下:
<Directory "D:/WAMP/WWW">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
另外也可以在 Indexes 前加一个减号 “-”,同样可以禁止Apache显示目录结构。
在Indexes前加 “+” 代表允许目录浏览;加 “-” 代表禁止目录浏览。修改如下:
<Directory "D:/WAMP/WWW">
Options -Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
如何防止Apache显示文件列表
转载上一篇:linux目录详解
下一篇:让你受用一辈子的一条CMD命令
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
如何防止U盘文件被拷贝?怎样保护U盘文件的安全?
如何防止U盘文件被拷贝?怎样保护U盘文件的安全?
备份文件 用户权限 自动备份 -
xcode中如何显示文件后缀
xcode显示文件后缀的贴心方法
xcode macos ide 显示文件 右键 -
windows如何显示文件扩展名称?
本文教程主要介绍一下,windows系统如何显示文件扩展名称。下面基于目前主流的操作系统版本(win7,win10,win11)1、
windows 扩展名 文件类型 显示文件