Different limit_req rules for different user agents
Valentin V. Bartenev
ne at vbart.ru
Mon Jun 18 13:06:31 UTC 2012
On Monday 18 June 2012 15:14:12 LexxTheFox wrote:
> Hello.
>
> I need to check client's user agent and apply different limit_req rules
> for different UAs.
> I've been trying to do it this way:
>
> http {
> limit_req_zone $binary_remote_addr zone=bots:10m rate=1r/m;
> server {
> ...
> location / {
> if ($http_user_agent ~* (google|bing|yandex|msnbot) )
> {
> limit_req zone=bots burst=5 nodelay;
> }
> include balancer.conf;
> }}}
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;
}
}
}
> But apparently I'm missing something as nginx -t says '[emerg]:
> "limit_req" directive is not allowed here'. Most likely due to poor
> understanding of configfile syntax.
http://nginx.org/r/limit_req
context: http, server, location
wbr, Valentin V. Bartenev
More information about the nginx
mailing list