Rate limiting for try_files

Marco Colli collimarco91 at gmail.com
Sat Jan 26 21:05:03 UTC 2019


Hello!

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?

Here's my configuration:

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=2r/s;

server {
listen 80;
server_name example.com;

        # serve the static file directly if it exists in the public Rails
folder...
try_files $uri @app;

location @app {
                # ... otherwise send the request to the Rails application
proxy_pass http://app;
proxy_redirect off;
}
}


I know that I can use the following:
limit_req zone=mylimit burst=50 nodelay;

However where should I put that line? 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).


Any help would be greatly appreciated
Thanks


Marco Colli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190126/6b414ccd/attachment.html>


More information about the nginx mailing list