dinggela 发表于 2018-11-20 07:37:04

apache限制 user_agent请求

  1、编辑虚拟主机配置文件
  vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
  2、在rewite模板添加参数
  修改rewrite模板条件将以下模板
  
  RewriteEngine on
  RewriteCond %{HTTP_HOST] ^www.aaa.com$
  RewriteRule ^/(.*)$ http://www.test.com/$1
  修改为:

  
  RewriteEngine on
  RewriteCond %{HTTP_HOST] ^www.aaa.com$
  RewriteRule ^/(.*)$ http://www.test.com/$1
  RewriteCond %{HTTP_USER_AGENT}^.*curl.*
  RewriteCond %{HTTP_USER_AGENT}^.*chrome*
  RewriteRule.*-
  
  3、使用curl 和chrome浏览器测试可否访问
  curl -x127.0.0.1:80 -I www.test.com/admin.php
  HTTP/1.1 403 Forbidden
  Date: Wed, 25 May 2016 09:24:54 GMT
  Server: Apache/2.2.31 (Unix) PHP/5.4.36
  Content-Type: text/html; charset=iso-8859-1
  (说明curl不可访问)
说明chrome浏览器不可访问



页: [1]
查看完整版本: apache限制 user_agent请求