Join the community today
Register Now

Nginx Rate limit per file?

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by BobbyWibowo, Oct 27, 2020.

  1. BobbyWibowo

    BobbyWibowo Active Member

    Jul 30, 2015
    Local Time:
    10:34 AM
    Hi there, is there an easy way to rate limit traffic in Nginx, but per file?
    I assumed it'd be possible with the limit_conn module, but I'm sorta having a hard time to figure out the specifics.

    To be exact, I need the rate limit to be shared globally per file. So if for example a specific file is already being accessed 1K times within a certain time frame, then subsequent requests to that specific file, no matter from who, will get rate limited.

    I have a file host service that's hosted on a very humble & old server, so it can only handle so much simultaneous traffics. Every now and then, there will be a file that somehow gets viral on whatever platform the uploader shares it, and brings in thousands of simultaneous traffic, only to that single file, yet that alone would already cause my server to choke.

    From a rough system resources reading that I did on some previous occasions, my bottleneck laid in the CPU, as it'd often get to 100% usage, with about half or more being occupied by iowait (which I later learned is I/O specific). All of the previous occasions were due to video files, so I suppose it only made sense it required plenty more I/O power or something.

    Thanks in advance!


    EDIT: The files that I need to get rate-limited are being accessed directly from a directory. No PHP, node service, or whatever else in between. Just plain ol' static files.