I have tried to rate limit a resource using HttpLimitReq that is passed
on to a backend Apache server. Now when I try to limit this resource,
nothing is blocked and all requests go through. When using static
resources, the limit_req works as expected. Here is my config:
I think this might be related to the execution order or these modules.
Which of the commands limit_req and proxy_pass is evaluated first? How
can I limit the access to resources in a backend server?
okay, I see. So nginx seems to (randomly?) choose one of the location
blocks - in my case it was the lower one using the proxy_pass directive.
However I have several scripts running under /cgi-bin that need
different limit_req settings - there are scripts that need to have a
strong limit and others do not need a limit at all. I have tried
something like
However I have several scripts running under /cgi-bin that need
different limit_req settings - there are scripts that need to have a
strong limit and others do not need a limit at all.
As Igor showed, use multiple location blocks.
I have tried something like
location /cgi-bin/ {
if ($request_filename ~ test.pl) {
Note that there’s also a special warning about if() inside location{}
at If is Evil… when used in location context | NGINX – anything other than “return” or
“rewrite … last” is likely to cause confusion.
…but unfortunately limit_req is not allowed in this context. Is there
another option how I could get limit_req to work for me?
If your scripts don’t use PATH_INFO, then something like