欢迎光临
我们一直在努力

Apache 禁止指定user_agent(防止爬虫扒取)

该功能可以禁止部分我们不需要的访问名单(),通过改写rewrite模块来实现。

tail /tmp/

tail  /usr/local/apache2/logs/test.com-access_20150121_log

 

在rewrite模块中添加如下信息:

RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^.*chrome* [NC]

RewriteRule .* – [F]

保存退出

测试

apachectl -t

apachectl restart

curl -x127.0.0.1:80 www.test.com/data/forum.php(默认403错误)

curl -x192.168.11.160:80 www.test.com/data/forum.php(默认403错误)

vi  /usr/local/apache2/conf/extra/httpd-vhosts.conf(注释掉)

# RewriteCond %{HTTP_USER_AGENT} ^.*curl.* [NC,OR]

apachectl -t

apachectl restart

curl -x192.168.11.160:80 www.test.com/adsjkf(404)

curl -x192.168.11.160:80 www.test.com/forum.php -I(200)

浏览器 www.test.com

curl -A “sdfsadsdfa”  -x192.168.11.160:80 www.test.com/forum.php -I

curl -A “sdfsadchrome  sdfa”  -x192.168.11.160:80 www.test.com/forum.php -I

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。