禁止访问Apache目录

在PHP网站开发中,基于WEB服务器和PHP网站程序代码的安全考虑,我们需要对相关的目录或者文件访问权限进行控制,以防止意外情况的发生,那么我们如何来实现这种功能呢?我们可以通过Apache来实现禁止目录访问(禁止游览列出的目录或文件列表)、禁止或允许IP与域名访问目录的功能。

 在Apache中配置禁止目录访问,即禁止游览列出的目录/文件列表的方法

  访问网站目录时Apache默认配置为可列出目录/文件列表,即当你访问http://localhost时会列出相关的目录和文件列表,我们可以通过修改Apache配置文件httpd.conf来实现禁止列出目录/文件列表,方法如下:

1、打开apache配置文件httpd.conf

2、找到







 
<Directory />
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>

 只需要修改Options Indexes为Options None即可,:根据PHP运行环境安装包的不同,Options Indexes也有可能是Options Indexes FollowSymLinks,一并改为Options None即可。

 

还需注意的事:如果是自己重新设置了DocumentRoot,例如以下:修改的地方也就不同了

<Directory "D:/Apache2/webpage">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
http://httpd.apache.org/docs/2.0/mod/core.html#options
# for more information.
#
   # Options Indexes FollowSymLinks
   Options  FollowSymLinks

#Indexes 的作用就是当该目录下没有 index.html 文件时,就显示目录结构,去掉 Indexes,Apache 就不会显示该目录的列表了。


# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

3、保存httpd.conf,并重启Apache即可,此时再访问http://localhost时, 报apache http 403 禁止访问错误信息

  Forbidden

  You don’t have permission to access / on this server.

   另一种方法是在指定的web目录下:http://jwc.jxatei.net:8080/  "index.html、index.php时",也可解决访问目录问题,但没有解决根本问题。 

  至此,通过配置Apache服务器我们可以实现禁止目录访问(列出目录或文件列表),这些功能对提高和优化WEB服务器的安全性能是必不可少的方法。

转载于:https://www.cnblogs.com/FanTasYX/p/3387615.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值