Search code examples
apache

What is the easy way to limit the download speed on apache host?


I'm trying something and I need to download a file with low speed from my website.(like 10KBps). Is there any easy way to set that speed limiter on server or host for only a specific directory?


Solution

  • Use the module mod_ratelimit which is included in httpd package.
    Here is an implementation on CentOS 7:

    1. Enable the mod_ratelimit module:

      vi /etc/httpd/conf.modules.d/00-base.conf
      

      uncomment line 72:

      LoadModule ratelimit_module modules/mod_ratelimit.so  
      
    2. Create a config file for mod_ratelimit:

      vi /etc/httpd/conf.d/ratelimit.conf  
      

      then put this content in:

      #limit bandwidth as 500KB/sec under the [apache_DocumentRoot_directory]/specific_directory
      <IfModule mod_ratelimit.c>
              <Location /specific_directory>
                  SetOutputFilter RATE_LIMIT
                  SetEnv rate-limit 500
              </Location>
      </IfModule>
      
    3. Restart your httpd service using:

      systemctl restart httpd.service