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.
$ 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
Related: How to manage Apache service
$ 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
Comment anonymously. Login not required.