码迷,mamicode.com
首页 > Web开发 > 详细

6_Apache 配置 之 禁止指用user_agent

时间:2016-10-01 06:40:30      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:user_agent

user_agent:限制一些垃圾访问


技术分享

 

在这个模块下面加,红色字体部分。

[root@OBird logs]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

<IfModule mod_rewrite.c>

      ReWriteEngine on

      ReWriteCond  %{HTTP_HOST} ^www.aaa.com$ [or]

      ReWriteCond  %{HTTP_HOST} ^www.bbb.com$

      ReWriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]

      ReWriteCond  %{HTTP_USER_AGENT}  ^.*curl.* [NC,OR] #NC 不区分大小写

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

      ReWriteRule  .* - [F]


    </IfModule>


[root@OBird logs]# apachectl -t

Syntax OK

[root@OBird logs]# apachectl restart

[root@OBird logs]# curl -x127.0.0.1:80 www.test.com/data/forum.php

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>403 Forbidden</title>    #都禁掉了,不能访问

</head><body>

<h1>Forbidden</h1>

<p>You don‘t have permission to access /data/forum.php

on this server.</p>

</body></html>

[root@OBird logs]# curl -x127.0.0.1:80 www.test.com/98989898

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>403 Forbidden</title>

</head><body>

<h1>Forbidden</h1>

<p>You don‘t have permission to access /98989898

on this server.</p>

</body></html>



注释掉这一行

  #ReWriteCond  %{HTTP_USER_AGENT}  ^.*curl.* [NC,OR] #NC 不区分大小写

就可以访问了。

[root@OBird logs]# curl -x127.0.0.1:80 www.test.com/forum.php -I

HTTP/1.1 200 OK

Date: Fri, 30 Sep 2016 05:54:07 GMT

Server: Apache/2.2.31 (Unix) PHP/5.6.24

X-Powered-By: PHP/5.6.24

Set-Cookie: k1rM_2132_saltkey=uQknMbNM; expires=Sun, 30-Oct-2016 05:54:07 GMT; Max-Age=2592000; path=/; httponly

Set-Cookie: k1rM_2132_lastvisit=1475211247; expires=Sun, 30-Oct-2016 05:54:07 GMT; Max-Age=2592000; path=/

Set-Cookie: k1rM_2132_sid=QvDlTX; expires=Sat, 01-Oct-2016 05:54:07 GMT; Max-Age=86400; path=/

Set-Cookie: k1rM_2132_lastact=1475214847%09forum.php%09; expires=Sat, 01-Oct-2016 05:54:07 GMT; Max-Age=86400; path=/

Set-Cookie: k1rM_2132_onlineusernum=1; expires=Fri, 30-Sep-2016 05:59:07 GMT; Max-Age=300; path=/

Set-Cookie: k1rM_2132_sid=QvDlTX; expires=Sat, 01-Oct-2016 05:54:07 GMT; Max-Age=86400; path=/

Cache-Control: max-age=0

Expires: Fri, 30 Sep 2016 05:54:07 GMT

Content-Type: text/html; charset=gbk


模拟访问

[root@OBird logs]# curl -A welcometobeijingchrome -x127.0.0.1:80 www.test.com/forum.php -I

HTTP/1.1 403 Forbidden

Date: Fri, 30 Sep 2016 05:57:35 GMT

Server: Apache/2.2.31 (Unix) PHP/5.6.24

Content-Type: text/html; charset=iso-8859-1

如果字眼里有 chrome  也是无法访问的。

本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1858125

6_Apache 配置 之 禁止指用user_agent

标签:user_agent

原文地址:http://20151213start.blog.51cto.com/9472657/1858125

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!