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.
$ 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 |
<VirtualHost *:80> # ..... # .... SetOutputFilter RATE_LIMIT SetEnv rate-limit 512 SetEnv rate-initial-burst 1024 </VirtualHost>
Documentation: Offcial documentation for mod_ratelimit
$ sudo systemctl restart apache2 # Ubuntu and Debian $ sudo systemctl restart httpd # CentOS and Red Hat
$ 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) |
Comment anonymously. Login not required.