zoukankan      html  css  js  c++  java
  • apache禁止訪问某些文件或文件夹的方法

    【apache配置禁止訪问】
    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>

    针对代理方式禁止对某些目标的訪问(<ProxyMatch> 能够用来正则匹配),比方拒绝通过代理訪问cnn.com:
    <Proxy http://cnn.com/*>
       Order allow,deny
       Deny from all
    </Proxy>

    2. 禁止某些IP訪问/仅仅同意某些IP訪问
    假设要控制禁止某些非法IP訪问。在Directory选项控制:
    <Directory "/var/www/web/">
       Order allow,deny
       Allow from all
       Deny from 10.0.0.1 #阻止一个IP
       Deny from 192.168.0.0/24 #阻止一个IP段
    </Directory>

    仅仅同意某些IP訪问。适合比方就同意内部或者合作公司訪问:
    <Directory "/var/www/web/">
       Order deny,allow
       Deny from all
       All from example.com #同意某个域名
       All from 10.0.0.1 #同意一个iP
       All from 10.0.0.1 10.0.0.2 #同意多个iP
       Allow from 10.1.0.0/255.255.0.0 #同意一个IP段,掩码对
       All from 10.0.1 192.168 #同意一个IP段,后面不填写
       All from 192.168.0.0/24 #同意一个IP段,网络号
    </Directory>


    Apache:解决的方法。
    <Directory "/home/domain/public_html">
    Options -Indexes FollowSymLinks
    AllowOverride All
    <Files ~ ".txt">
    Order allow,deny
    Deny from all
    </Files>
    </Directory>
  • 相关阅读:
    常用head标签
    php自定义配置文件简单写法
    sublimeText常用插件
    addslashes,htmlspecialchars,htmlentities转换或者转义php特殊字符防止xss攻击以及sql注入
    服务器安装node全教程
    Sublime Text 3 Build 3176 License
    [转]Zend Studio 文件头和方法注释设置
    给php代码添加规范的注释phpDocumentor
    [转]php 在各种web服务器的运行模式
    .htaccess文件url重写小记
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7112509.html
Copyright © 2011-2022 走看看