1. 程式人生 > >【CentOS 7架構16】,限制user_agent#

【CentOS 7架構16】,限制user_agent#

shallow丿ove


訪問控制——user_agent

  • user_gaent可以理解為瀏覽器標識
  • 核心配置檔案內容 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{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