zoukankan      html  css  js  c++  java
  • Apache设置禁止访问网站目录(目录列表显示文件)

    默认apache在当前目录下没有index.html入口就会显示目录。让目录暴露在外面是非常危险的事,如下操作禁止apache显示目录,希望文章对各位有帮助。

    进入apache的配置文件 httpd.conf 找到:

     代码如下 复制代码

    Options Indexes FollowSymLinks

    修改为:

    Options FollowSymLinks

    其实就是将Indexes去掉,Indexes表示若当前目录没有index.html就会显示目录结构。

     代码如下 复制代码

    1. 禁止访问某些文件/目录
    增加Files选项来控制,比如要不允许访问 .inc 扩展名的文件,保护php类库:
    <Files ~ ".inc$">
    Order allow,deny
    Deny from all
    </Files>

    禁止访问某些指定的目录:(可以用 <DirectoryMatch>   来进行正则匹配)
    <Directory ~ "^/var/www/(.+/)*[0-9]{3}">
    Order allow,deny
    Deny from all
    </Directory>

    通过文件匹配来进行禁止,比如禁止所有针对图片的访问:
    <FilesMatch .(?i:gif|jpe?g|png)$>
    Order allow,deny
    Deny from all
    </FilesMatch>

    针对URL相对路径的禁止访问:
    <Location /dir/>
    Order allow,deny
    Deny from all
    </Location>

    配置示例:

     代码如下 复制代码
    <Directory "E:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
    #
    # 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.
    # 就是这一行,只去掉indexes也可
    #Options Indexes FollowSymLinks
    Options FollowSymLinks
    #
    # 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>
    建议默认情况下,设置APACHE禁止用户浏览目录内容。
  • 相关阅读:
    Debian8搭建LEMP环境
    ProjectManager Beta 7 项目管理器发布
    我的Linux软件集
    修改/home内子目录的名字
    Nginx配置特定二级域名
    Debian8 安装wordpress博客
    LinuxMint18使用单独分区作为Home挂载点
    LinuxMint18配置Grub2默认启动操作系统
    《失恋33天》从绝境中走出来的故事
    爱的世界很拥挤,写在读《爱,就这么简单》之后
  • 原文地址:https://www.cnblogs.com/kenshinobiy/p/4463353.html
Copyright © 2011-2022 走看看