apache 2.4权限配置

Order命令已从Apache 2.4中删除

注意:使用require指令时,需要在指令外添加<RequireAll></RequireAll>标签对,否则重启Apache2.4加载规则时将出现错误:" negative Require directive has no effect in <RequireAny> directive "。

下面直接给出一些实例对Require指令的使用进行说明:

例1:允许所有访问请求

Apache2.4下的配置:

<Directory xxx/www/yoursite>

    <RequireAll>
Require all granted
</RequireAll> </Directory>

  

例2:拒绝所有访问请求

Apache2.4下的配置:

<Directory xxx/www/yoursite>

    <RequireAll>
Require all denied
</RequireAll> </Directory>

例3:只允许来自特定域名主机的访问请求,其他请求将被拒绝

<Directory xxx/www/yoursite>

    <RequireAll>
Require host google.com
</RequireAll> </Directory>

  

例4:只允许来自特定IP或IP段的访问请求,其他请求将被拒绝

Apache2.4下的配置:

<Directory xxx/www/yoursite>

    <RequireAll>
Require ip 192.120 192.168.100 192.168.1.1
</RequireAll> </Directory>

例5:允许所有访问请求,但拒绝来自特定IP或IP段的访问请求(阻止恶意IP或恶意爬虫网段的访问)

Apache2.4下的配置:

<Directory xxx/www/yoursite>

    <RequireAll>
Require all granted
Require not ip 192.168.1.1
Require not ip 192.120 192.168.100
</RequireAll> </Directory>

  

例6:允许所有访问请求,但拒绝某些User-Agent的访问请求(通过User-Agent屏蔽垃圾网络爬虫)

使用mod_setenvif通过正则表达式匹配来访请求的User-Agent,并设置内部环境变量BADBOT,最后拒绝BADBOT的访问请求。

Apache2.4下的配置:

<Directory xxx/www/yoursite>

    SetEnvIfNoCase User-Agent ".*(FeedDemon|JikeSpider|AskTbFXTV|CrawlDaddy|Feedly|Swiftbot|ZmEu|oBot).*" BADBOT
SetEnvIfNoCase User-Agent "brandwatch" BADBOT
SetEnvIfNoCase User-Agent "rogerbot" BADBOT
<RequireAll>
Require all granted
Require not env BADBOT
Require not ip 192.168.100.1
</RequireAll> </Directory>

  

其它require访问控制指令用法如下:

Require all granted #允许所有
Require all denied #拒绝所有
Require env env-var [env-var] ... #允许匹配环境变量中任意一个
Require method http-method [http-method] ... #允许特定的HTTP方法(GET/POST/HEAD/OPTIONS)
Require expr expression #允许,表达式为true
Require user userid [ userid ] ... #允许特定用户
Require group group-name [group-name] ... #允许特定用户组
Require valid-user # #允许,有效用户
Require ip 192.100 192.168.100 192.168.100.5 #允许特定IP或IP段,多个IP或IP段间使用空格分隔

  

了解更多require指令用法:《Apache Module mod_authz_core》

apache 2.2 和 2.4 访问控制区别 (require 替代 deny)的更多相关文章

  1. 在apache2.4版本之前做客户端访问控制,是用Allow Deny Order指令做访问控制的,

    在apache2.4版本之前做客户端访问控制,是用Allow Deny Order指令做访问控制的,而在2.4的版本上是用的用法跟之前的版本大不相同,如下 ###################### ...

  2. nginx、apache和tomcat之间的关系和区别

    Apache/Nginx 应该叫做 HTTP Server,即安装后生成httpd服务. Tomcat 则是一个 Application Server,或者更准确的来说,是一个「Servlet/JSP ...

  3. Java基础知识强化98:Apache和Tomcat服务器的联系与区别

    1. Apache 和 Tomcat 都是web网络服务器,两者既有联系又有区别,在进行HTML.PHP.JSP.Perl等开发过程中,需要准确掌握其各自特点,选择最佳的服务器配置. Apache是w ...

  4. 【转】Apache与Tomcat有什么关系和区别

    [原文链接:https://www.cnblogs.com/zangdalei/p/8057325.html] Apache 和 Tomcat 都是web网络服务器,两者既有联系又有区别,在进行HTM ...

  5. Apache与Tomcat有什么关系和区别

    Apache 和 Tomcat 都是web网络服务器,两者既有联系又有区别,在进行HTML.PHP.JSP.Perl等开发过程中,需要准确掌握其各自特点,选择最佳的服务器配置. Apache是web服 ...

  6. JavaWeb - Apache与Tomcat有什么关系和区别

    总结: 1- apache是web服务器,侧重于http server: tomcat是应用(java)服务器,侧重于servlet引擎 2-合作过程详解,请看:JavaWeb - apache和to ...

  7. Apache服务器和tomcat服务器有什么区别(转)

    Apache与Tomcat都是Apache开源组织开发的用于处理HTTP服务的项目,两者都是免费的,都可以做为独立的Web服务器运行.Apache是Web服务器而Tomcat是Java应用服务器. A ...

  8. org.springframework.beans.BeanUtils与org.apache.commons.beanutils.BeanUtils的copyProperties用法区别

    知识点 org.springframework.beans.BeanUtils与org.apache.commons.beanutils.BeanUtils都提供了copyProperties方法,作 ...

  9. Apache服务器和tomcat服务器有什么区别?

    Apache与Tomcat都是Apache开源组织开发的用于处理HTTP服务的项目,两者都是免费的,都可以做为独立的 Web服务器运行.Apache是Web服务器而Tomcat是Java应用服务器. ...

随机推荐

  1. <html> ---- position

    position 固定的属性,是全局的.和DIV层次无关. <!DOCTYPE html> <html lang="en"> <head> &l ...

  2. Sql Prompt---Unable to connect to the Redgate Client Service

    今天在使用SQLPrompt时,突然发现所有的提示都不能用了,在百度上搜索无果,刚刚在Google搜索,果然找到了自己想要的答案,今天把搜索的结果发布在此,希望能够帮助到有需要的朋友. 客户端服务停止 ...

  3. wpf binging(五) 数据的转换与验证

    1.数据的验证,有时候需要验证同步的数据是否正常 需要派生一个类 ValidationRule 再把这个类指定给binging 进行验证 在这里如果验证不通过 textbox就会变成红色并且发出警告数 ...

  4. org.springframework.beans.factory.BeanCreationException 解决异常错误

    一月 18, 2017 10:18:51 上午 org.apache.coyote.http11.Http11Protocol initINFO: Initializing Coyote HTTP/1 ...

  5. 正则表达式andJS内存空间详细图解

    http://www.runoob.com/js/js-regexp.html https://blog.csdn.net/pingfan592/article/details/55189622

  6. 学习笔记--python中使用多进程、多线程加速文本预处理

    一.任务描述 最近尝试自行构建skip-gram模型训练word2vec词向量表.其中有一步需要统计各词汇的出现频率,截取出现频率最高的10000个词汇进行保留,形成常用词词典.对于这个问题,我建立了 ...

  7. 3.14 unittest之skip

    3.14 unittest之skip 前言当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例.或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用 ...

  8. ros 使用笔记

    1. publishers/subscribers 常用指令    说明rosnode list    查看所有激活的节点rostopic list    查看所有激活的topicrostopic i ...

  9. 【论文阅读】Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks

    Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks 参考 1. 人脸关键点: 2. ...

  10. javascript 之 继承

    1.传统方式--->原型链  (过多继承了没用的属性) Grand.prototype.lastname = 'zhang' function Grand(); } var grand = ne ...