Apache, by default, will serve files to the users as fast as the bandwidth or TCP/IP allows. In an environment where you are hosting files for download, and you don't want a single user to hog your server's bandwidth, you might want to throttle the download speed for your users. It allows your server to serve more users at a time.

You can limit the download speed of your Apache users by using mod_ratelimit. You have the option to specify the desired speed for each Location or VirtualHost configuration.

Steps to throttle download speed on Apache:

  1. Launch your preferred terminal application.
  2. Enable ratelimit module for Apache.
    $ sudo a2enmod ratelimit #Ubuntu, Debian and SUSE
    Considering dependency env for ratelimit:
    Module env already enabled
    Enabling module ratelimit.
    To activate the new configuration, you need to run:
      systemctl restart apache2

    Distribution with a2enmod support can simply run the command above without having to manually enable the required modules.

    Options Debian, Ubuntu openSUSE and SLES Fedora Core, CentOS, RHEL macOS homebrew xampp
    a2enmod support yes yes no no no no
    Modules to install none
    Module name n/a ratelimit
    Loadmodule directive n/a LoadModule ratelimit_module <module_locations>/mod_ratelimit.so
  3. Add relevant options in Apache configuration file for a specific Location or VirtualHost configuration where you want the bandwidth to be limited.
    <VirtualHost *:80>
            # .....
            # ....
            SetOutputFilter RATE_LIMIT
            SetEnv rate-limit 512
            SetEnv rate-initial-burst 1024
  4. Restart Apache service for the changes to take effect.
    $ sudo systemctl restart apache2 #Ubuntu and Debian
    $ sudo systemctl restart httpd # CentOS and Red Hat
  5. Download a file from the server to see if the bandwitdth is correctly limited.
    $ curl --output image.iso www.simplified.guide/image.iso
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
      3  512M    3 19.7M    0     0   538k      0  0:16:13  0:00:37  0:15:36  508k
Discuss the article:

Comment anonymously. Login not required.