当前位置: 移动技术网 > 网络运营>服务器>Linux > Apache安全配置之禁止目录访问的配置方法

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

2019年05月02日  | 移动技术网网络运营  | 我要评论
在php网站开发中,为了让网站目录文件和程序代码的安全考虑,我们必须对某些目录或者文件的访问权限进行控制,来提高网站的安全,那么我们怎样来实现这种功能呢?这时候可以配置ap

在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.php这些默认的文件时,就会报apache http 403 禁止访问错误信息:

复制代码 代码如下:
forbidden
you don't have permission to access / on this server.

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网