访问控制——user_agent

  • user_gaent可以理解为浏览器标识
  • 核心配置文件内容<IfModule mod_rewrite.c>RewriteEngine onRewriteCond %{HTTP_USER_AGENT} .curl. [NC,OR]RewriteCond %{HTTP_USER_AGENT} .baidu [NC]RewriteRule .* - [F]</IfModule>
  • curl -A "123123" 指定user_agent
[root@localhost ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
     48 #       Deny from all
     49 #       </FilesMatch>
     50     <IfModule mod_rewrite.c>
     51         RewriteEngine on
     52         RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR]
     53         RewriteCond %{HTTP_USER_AGENT} .*baidu.* [NC]
     54         RewriteRule .* - [F]
     55    </IfModule>
     56     </Directory>
     57     <Directory /data/wwwroot/111.com>
     58         <FilesMatch user.php(.*)>
     59         Order deny,allow
     60         Deny from allow
     61         Allow from 127.0.0.1
     62         </FilesMatch>
     63     </Directory>
[root@localhost ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@localhost ~]# /usr/local/apache2.4/bin/apachectl graceful
403
[root@localhost ~]# tail /usr/local/apache2.4/logs/111.com-access_20171105.log

07-04 05:42