Conditional limit_req
Guilherme
guilherme.e at gmail.com
Thu May 3 19:34:57 UTC 2012
Hello,
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:
-------------------------------------------------------------------------------------
limit_req_zone $http_host zone=one:10m rate=1r/s;
upstream redisbackend {
server 127.0.0.1:6379;
}
server {
listen xxxxx:80 default_server;
location = /redis {
internal;
redis2_query get $arg_key;
redis2_pass redisbackend;
}
location / {
default_type 'text/html';
set $backendserver '';
set $limit '';
access_by_lua '
local key = ngx.var.http_host
local res = ngx.location.capture(
"/redis", { args = { key = key } }
)
m = ngx.re.match(res.body, "([a-z]+):([0-9\.]+):([0-9]+)")
if m ~= nil then
user = m[1]
ngx.var.backendserver = m[2]
ngx.var.limited = tonumber(m[3])
end
';
if ($limited = 1) {
limit_req zone=one burst=2;
}
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://$backendserver:888;
break;
}
}
------------------------------------------------------------------------------------------------------------------------------
When I reload nginx I'm getting the following error:
nginx: [emerg] "limit_req" directive is not allowed here in
/etc/nginx/conf.d/default.conf:64
Is there a way to limit specific websites using just 1 virtual host (server
directive)?
Regards,
Guilherme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20120503/aa94d668/attachment.html>
More information about the nginx
mailing list