limit_req_zone: How to apply only to some requests containing some string in the URL?

Francis Daly francis at daoine.org
Wed Oct 23 08:09:10 UTC 2013


On Tue, Oct 22, 2013 at 11:42:35PM -0400, Brian08275660 wrote:

Hi there,

> I'm using the limit_req_zone module. I would like it to act only on some
> requests that have a certain string in one variable in the query string of
> the URL.

> http://api.acme.com/ipgeolocation/locate?key=NANDSBFHGWHWN2X&ip=146.105.11.59
> 
> I would like the rule to detect when the "key" parameter ends with "2X", and
> in such case to apply the limitation. 

http://nginx.org/r/limit_req_zone

See $variable.

Use, for example, "map" to make your variable have a value when you want
the limit to apply, and be empty when you don't.

> What I really need is to give NGINX a secret message. The "key" parameter
> would end in "01X",  "02X", "03X" (etc). This would indicate Nginx the
> limitation of queries per minute, and Nginx would apply a different rate for
> each request, depending on the "message".

For that, I think you'd need a different limit_req zone for each rate.

After you've got the first part working, it shouldn't be too hard to
set up a test system to see if you can get this part to work too.

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list