Welcome! Log In Create A New Profile

Advanced

Re: Rate limiting for try_files

Francis Daly
January 27, 2019 04:44PM
On Sat, Jan 26, 2019 at 10:05:03PM +0100, Marco Colli wrote:

Hi there,

> I cannot figure out how to apply a rate limit *only to static files* served
> with try_files (and not for @app location). Is it possible?

The request is handled in a location. Only the config in, or inherited
in to, that location matters. For try_files files, the location is the
one that the try_files is in.

> server {

> try_files $uri @app;

Does it break anything to put that inside "location / {}"?

> location @app {

> I know that I can use the following:
> limit_req zone=mylimit burst=50 nodelay;
>
> However where should I put that line?

In the location that you want it to apply.

> If I put it in the "server", then
> also my @app will use that settings, which is not what I want... I just
> want to put a limit specific for files served using try_files. Note that
> static files can be in any location, even the root folder (e.g.
> /favicon.ico and many others).

Put it in each of those location{}s too.

> Any help would be greatly appreciated

The other option is to apply the limit_req at server level, so that it
will inherit in to all locations{}s that do not have their own limit_req
directive.

And then add a "no limit" limit_req directive in those location{}s.

I think that you can do *that*, by adding something like

limit_req_zone "" zone=off:32k rate=7r/m;

(where "" is a key that will always be empty and so will not limit
anything; "off" is a string to use as the zone name, "32k" is the
minimum size allowed on my test machine (8x page size), and the "rate"
is something that is odd enough that you will hopefully recognise if if
things go wrong, and this *does* ever start limiting anything.)

and then adding "limit_req zone=off;" in the appropriate places.

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rate limiting for try_files

Marco Colli January 26, 2019 04:06PM

Re: Rate limiting for try_files

Francis Daly January 27, 2019 04:44PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 188
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready