Managing bandwidth is crucial for servers, especially when multiple clients download large files simultaneously. By controlling the speed or throttling download speeds, you can provide a balanced and efficient distribution of resources, ensuring all users receive optimal performance.

Apache, one of the most popular web servers, provides a range of modules and configurations allowing web administrators to control and throttle download speeds. One commonly used module is mod_ratelimit. When enabled and correctly configured, this module allows you to set a cap on the download speed for clients.

While many distributions come with mod_ratelimit, you might need to enable or configure it to suit your server's requirements. Below, you'll find steps to enable and configure download speed throttling on your Apache server.

Steps to throttle download speed on Apache:

  1. Launch terminal.
  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>/
  3. Open your Apache configuration file or virtual host file using a text editor.
    $ sudo vi /etc/apache2/sites-available/000-default.conf
  4. Add mod_ratelimit options within specific Location, Directory or VirtualHost directive where you want the bandwidth to be limited.
    <VirtualHost *:80>
            # .....
            # ....
            SetOutputFilter RATE_LIMIT
            SetEnv rate-limit 512
            SetEnv rate-initial-burst 1024

    The above configuration limits download speed to 512 KB/s after an initial burst of 1MB. Adjust the values as required.

  5. Save the file and close the text editor.
  6. Restart Apache to apply the changes.
    $ sudo systemctl restart apache2 # Ubuntu and Debian
    $ sudo systemctl restart httpd # CentOS and Red Hat
  7. Download a file from the server to see if the bandwitdth is correctly limited.
    $ curl --output 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.