Different limit_req rules for different user agents

LexxTheFox nginx-forum at nginx.us
Mon Jun 18 11:14:12 UTC 2012


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;
}}}

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. Please advice me on how to achieve
my goal.

Thanks in advance.

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



More information about the nginx mailing list