天天看点

Centos7.2 Apache根据User-Agent设置访问禁止

Apache可以设置资源的访问限制,在配置文件里通过mod_authz_host模块设置限制,这是在apache,2.4版本及以后中才有的模块,在2.2版本,是通过Order,Allow,Deny指令来实现限制功能。

这里记录下apache 的设置:

$ vim /etc/httpd/conf/httpd.conf (  修改apache配置文件 )

------------------------------------------------------------------------------------------------------

<Directory xxx/www/yoursite> #指定资源

SetEnvIfNoCase User-Agent ".*(FeedDemon|JikeSpider|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>

---------------------------------------------------------------------------------------------------

根绝自己需要自定 限制规则,然后重启服务即可生效。

Apche 的mod_authz_host 模块的其他使用方法如下:

---------------------------------------------------------------------------------------------------------

Require all granted #允许所有

Require all denied #拒绝所有

Require env env-var env-var #允许匹配环境变量中任意一个

Require method http-method http-method #允许特定的HTTP方法(GET/POST/HEAD/OPTIONS)

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段间使用空格分隔

---------------------------------------------------------------------------------------------------------

好的,就到这里,记录一下,共同学习。