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

You can limit the download speed of your Apache users by using mod_ratelimit and 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 and Debian
    [sudo] password for user:
    Enabling module ratelimit.
    To activate the new configuration, you need to run:
      systemctl restart apache2
  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
    </VirtualHost>
  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

Guide compatibility:

Operating System
Ubuntu 16.04 LTS (Xenial Xerus)
Ubuntu 16.10 (Yakkety Yak)
Ubuntu 17.04 (Zesty Zapus)
Ubuntu 17.10 (Artful Aardvark)
Ubuntu 18.04 LTS (Bionic Beaver)
Ubuntu 18.10 (Cosmic Cuttlefish)
Ubuntu 19.04 (Disco Dingo)
Discuss the article:

Comment anonymously. Login not required.

Share!