Quantcast
Channel: Nginx Forum - Nginx Mailing List - English
Viewing all articles
Browse latest Browse all 7229

limit_req and limit_conn in rewrite modules if statement (2 replies)

$
0
0
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?

Viewing all articles
Browse latest Browse all 7229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>