Conditional limit_req

Francis Daly francis at
Sat May 5 11:07:54 UTC 2012

On Thu, May 03, 2012 at 04:34:57PM -0300, Guilherme wrote:

Hi there,

all of this is untested by me, so consider it as a "maybe it's worth
trying" rather than a "here is how to do it".

> I'm using httpluamodule+redis to make a dynamic proxy to use in a mass
> vhost environment. I need to limit requests/s for specifics http_host. I
> tried to do something like that:

You want to limit incoming requests for specific http_host values.

This means that somewhere, you will have to enumerate which http_host
values should be restricted (or which should be unrestricted -- whichever
list is easier).

I would probably use multiple server blocks -- one as "default_server"
and the other with the server_name list to be restricted.

Then include limit_req in one server block, and not in the other.


> Is there a way to limit specific websites using just 1 virtual host (server
> directive)?

...if you don't want to do that, then...

maybe use "map" to set a variable "$my_limit_variable" which is either
$http_host or empty; then use "limit_req_zone $my_limit_variable", and
"limit_req" unconditionally -- expecting that the empty variable will
not be restricted?

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list