6_Apache 配置 之 禁止指用user_agent
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6_Apache 配置 之 禁止指用user_agent相关的知识,希望对你有一定的参考价值。
user_agent:限制一些垃圾访问
在这个模块下面加,红色字体部分。
[[email protected] 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>
[[email protected] logs]# apachectl -t
Syntax OK
[[email protected] logs]# apachectl restart
[[email protected] 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>
[[email protected] 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 不区分大小写
就可以访问了。
[[email protected] 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
模拟访问
[[email protected] 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的主要内容,如果未能解决你的问题,请参考以下文章
LAMP(apache禁止解析php,限制user_agent,php配置,open_bashdir
限定某个目录禁止解析php 限制user_agent php相关配置
11.28 限定某个目录禁止解析php 11.29 限制user_agent 11.30/11.31 php相关配置