灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:2799回复:0

Apache安全配置之禁止目录访问的配置方法

楼主#
更多 发布于:2014-06-03 09:58

这篇文章主要介绍了Apache禁止目录访问的配置方法,这是一个常见的、非常有必要的apache安全配置之一,需要的朋友可以参考下

在PHP网站开发中,为了让网站目录文件和程序代码的安全考虑,我们必须对某些目录或者文件的访问权限进行控制,来提高网站的安全,那么我们怎样来实现这种功能呢?这时候可以配置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即可。

保存httpd.conf,重启apache。如果此时不行,继续修改下面的配置:

 代码如下:

 

<Directory "E:/web">

    #

    # 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.2/mod/core.html#options

    # for more information.

    #

    Options none

    #

    # 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  时,如果没有index.html或者index.php这些默认的文件时,就会报apache http 403 禁止访问错误信息:

 代码如下:

Forbidden

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


喜欢0 评分0
游客

返回顶部