6_Apache 配置 之 禁止指用user_agent

來源:互聯網
上載者:User

標籤:user_agent

user_agent:限制一些垃圾訪問


650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/88/48/wKioL1ft4DCAQrgxAAXKwe7WQGc406.jpg" title="dis23.jpg" alt="wKioL1ft4DCAQrgxAAXKwe7WQGc406.jpg" />

 

在這個模組下面加,紅色字型部分。

[[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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.