Download Speed Limit and Throttling for Apache 2.4

Restricting download speeds is extremely easy with Apache 2.4, which now comes standard with mod_ratelimit (a very simple and straight-forward module).

Download limits can be set per:

  • Server (all websites)
  • VirtualHost (specific website)
  • URL

The download limit will be applied per download connection, restricting each download to a specific maximum speed.

Load mod_ratelimit

Add the loading of mod_ratelimit into Apache’s configuration.

<IfVersion >= 2.4>
    LoadModule ratelimit_module modules/

Limit Download Speed

To limit download speed per URL in a specific website, open the website’s VirtualHost files (both the HTTP and SSL VH), and insert the rate limiting configuration inside the VirtualHost block.

This example sets the limit to 350KB/s for all downloads under URL “/downloads”.

<IfModule mod_ratelimit.c>
    <Location /downloads>
        SetOutputFilter RATE_LIMIT
        SetEnv rate-limit 350

Save file(s), and restart Apache for configuration changes to take effect.

Test Bandwidth Throttling

Place a large file into the /downloads location, and attempt to download this file multiple times. Check the results –


* This works best under IE, as Chrome will not download the same file multiple times at the same time.

More Specific Limits

Anything other then per connection limits require more comprehensive Apache modules such as mod_bw (docs) or mod_limitipconn (docs).

*mod_security can also limit bandwidth, but I would not recommend it as it’s too complex to setup, use, and maintain.

Also, according to the mod_ratelimit docs (well, the comments in the docs), you can dynamically adjust this rate limit per request, using PHP…

Note that if you are using PHP, you can set rate-limit to 0 in httpd.conf (no limiting) and then dynamically set “rate-limit” env variable for each request in your PHP scripts, but you cannot use putenv() function for this. You must use apache_setenv() in order to make it work properly.

This could allow you to create your own management script that tracks the use of, and allots, the download bandwidth.

7 thoughts on “Download Speed Limit and Throttling for Apache 2.4”

  1. That’s what I am looking for. We have to provide Software to downlaod for teammembers all over the world but we will prevent them to download with as much as bandwith they have

    Thanks for you article.

  2. Hello. Well this only allow limiting download speed (from server to client). Can you explain how to limit upload speed (from client to server) like for uploading pictures. I’ve tried this but it does not seem to work:

    SetOutputFilter RATE_LIMIT
    SetEnv rate-limit 350

    1. I don’t think that is possible to control/limit client upload speeds via Apache.

      You would likely have to do external rate limiting (throttle upload) outside by using the Router (with its QoS / or any other throttling features provided) or via Windows own QoS (Quality of Service) on the network layer.

      You would set up a separate uploads sub-domain (same server, but perhaps different port), or on another LAN server / IP, do the above, and then use ProxyPass to connect it back to the front-end Apache server (if need be).

      Or use an FTP solution.

  3. sir i need some help in this. i have just 2 requirements , so hope you can help me .
    1st. download speed per url not more than 3Mbps –> this i understand can be done by above your tutorial
    2nd. now of connection per url (in download manager supporting threads) not more than 8. Some user set 16 or above and hence our servers are at high load.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>