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>
     
  • 相关阅读:
    面向过程--面向对象
    shiro有哪些组件?
    Redis的特点什么是?
    Spring Boot 有哪些优点?
    什么是 JavaConfig?
    HashMap和Hashtable的区别
    深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
    Linux指令--tar,gzip
    JQuery 学习总结及实例
    $(this) 和 this 关键字在 jQuery 中有何不同?
  • 原文地址:https://www.cnblogs.com/cuizhipeng/p/5329856.html
Copyright © 2011-2022 走看看