6_Apache 配置 之 禁止指用user_agent
user_agent:限制一些垃圾访问在这个模块下面加,红色字体部分。
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
ReWriteEngine on
ReWriteCond%{HTTP_HOST} ^www.aaa.com$
ReWriteCond%{HTTP_HOST} ^www.bbb.com$
ReWriteRule ^/(.*)$ http://www.test.com/$1
ReWriteCond%{HTTP_USER_AGENT}^.*curl.* #NC 不区分大小写
ReWriteCond%{HTTP_USER_AGENT}^.*chrome*
ReWriteRule.* -
# apachectl -t
Syntax OK
# apachectl restart
# curl -x127.0.0.1:80 www.test.com/data/forum.php
403 Forbidden #都禁掉了,不能访问
Forbidden
You don't have permission to access /data/forum.php
on this server.
# curl -x127.0.0.1:80 www.test.com/98989898
403 Forbidden
Forbidden
You don't have permission to access /98989898
on this server.
注释掉这一行
#ReWriteCond%{HTTP_USER_AGENT}^.*curl.* #NC 不区分大小写
就可以访问了。
# 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
模拟访问
# 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也是无法访问的。
页:
[1]