Different limit_req rules for different user agents

LexxTheFox nginx-forum at nginx.us
Thu Jun 21 11:46:12 UTC 2012


Valentin V. Bartenev Wrote:
-------------------------------------------------------

>   http {
> 
>       map $http_user_agent $limit_bots {
>           default '';
>           ~*(google|bing|yandex|msnbot)
> $binary_remote_addr;
>       }
> 
>       limit_req_zone $limit_bots zone=bots:10m
> rate=1r/m;
> 
>       server {
>           location / {
>               limit_req zone=bots burst=5 nodelay;
>           }
>       }
>   }
>
>  wbr, Valentin V. Bartenev

Hello.

I still don't really get the 'map' magic. This example does not work for
me - bots still connect as often as they please. But your example gave
me an idea. After some reading and fiddling I managed to solve the
riddle this way:

http {
limit_req_zone $limit_bots zone=bots:10m rate=1r/m;
       server {
          location / {
            set $bot '';
            if ($http_user_agent ~* (google|bing|yandex|msnbot) ) {set
$limit_bots $binary_remote_addr;}
            limit_req zone=bots burst=5 nodelay;
           }
       }
   }

I will continue reading docs and hope to figure everything out
eventually. By now it works for me.

Thank you for your help!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,227641,227759#msg-227759



More information about the nginx mailing list