Welcome! Log In Create A New Profile

Advanced

limit_req and limit_conn in rewrite modules if statement

Nam
November 18, 2013 02:49PM
Hello, I would like to see if it's possible to get limit_conn and limit_req working with the rewrite modules if statement. I have seen some discussion about this in the mailing list already saying to use stuff like throwing a 410 code and having that 410 code handled by a @named location that handles requests that should not be limited, such as ...

location / {
error_page 410 = @nolimit;

if ($http_user_agent ~ Googlebot) {
return 410;
}

limit_req zone=one burst=4;

...
}

location @nolimit {
...
}

I also know about how if statements are considered evil and should be avoided where possible, but I am working with dynamically generating config files which support multiple upstreams, with different upstream options per location directive with various features involved. I would like to be able to set a variable that I can than use in an if statement to determine if limit_con or limit_req should be used. For example...

set $Whitelisted "No";
if ($http_user_agent ~ (googlebot|bingbot)) {
set $Whitelisted "Yes";
}
if ($Whitelisted ~* "No") {
limit_conn conlimit-one 5;
limit_req zone=limit-half burst=9;
}

Is there any possibility of this functionality being unlocked in the nginx code? I really need this functionality, and I hope it's not a big deal to do.
Is there are particular reason why this module does not work with the rewrite if statement?
Subject Author Posted

limit_req and limit_conn in rewrite modules if statement

Nam November 18, 2013 02:49PM

Re: limit_req and limit_conn in rewrite modules if statement

Nam November 18, 2013 03:57PM

Re: limit_req and limit_conn in rewrite modules if statement

Jonathan Matthews November 18, 2013 04:06PM

Re: limit_req and limit_conn in rewrite modules if statement

Nam November 18, 2013 06:23PM

Re: limit_req and limit_conn in rewrite modules if statement

Francis Daly November 18, 2013 07:36PM

Re: limit_req and limit_conn in rewrite modules if statement

Nam November 19, 2013 01:47PM

Re: limit_req and limit_conn in rewrite modules if statement

Maxim Dounin November 26, 2013 11:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 272
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready