Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»Apache»How to Limit Bandwidth and Connections in Apache on CentOS

    How to Limit Bandwidth and Connections in Apache on CentOS

    By RahulJuly 3, 20142 Mins Read

    The mod_bw Apache module provides the capability to limit bandwidth used by Virtualhost or limit max number of connections to any virtualhost. this can be helpful for those sites which provides large number of files to download for their users. This article will help you Setup limit bandwidth and connections in Apache on CentOS/Redhat systems.

    Advertisement

    1- Install mod_bw Module:

    For yum based system, mod_bw is available under EPEL yum repository, So make sure you have enabled epel repository in system.

    # yum install mod_bw
    

    2- Limit Bandwidth in Apache:

    After installing mod_bw module, Lets edit module configuration file /etc/httpd/conf.d/mod_bw.conf and add below line only, remove all other settings from file.

    LoadModule bw_module modules/mod_bw.so
    

    Now edit Apache Virtualhost and set the bandwidth like below.

    <Virtualhost *:80>
        ...
        ...
        <Directory "/var/www/html">
    	BandWidthModule On
    	ForceBandWidthModule On
    	BandWidth all 1000  # in bytes/sec
        </Directory>
    </Virtualhost>
    

    Description of parameters.

    BandWidthModule is set to [On|Off] to enable or disable bandwidth on virtualhost.
    ForceBandWidthModule is set to [On|Off] to force bandwidth limit for each request made on virtualhost by end users.
    BandWidth is use to set the limit on specific users or all users. This takes 2 parameters. From is the origin of the connections. It could be a full host, part of a domain, an ip address, a network mask (i.e # 192.168.0.0/24 or 192.168.0.0/255.255.255.0) or all. # The second parameter indicates the total speed available to the Origin.# If speed is 0, there is no limit.

    After making all required configurations restart apache service.

    # service httpd restart
    

    3- Limit Connections in Apache:

    To Limit maximum connection from all hosts for specific hosts we can use MaxConnection in virutalhost like below.

    <Virtualhost *:80>
        ...
        ...
        <Directory "/var/www/html">
    	BandWidthModule On
    	ForceBandWidthModule On
    	BandWidth all 1000   # in bytes/sec
            MaxConnection all 10
       </Directory>
    </Virtualhost>
    

    After making all required configurations restart apache service to take effect new chnages.

    # service httpd restart
    

    Apache bandwidth virtualhost webserver
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How To Set Up Nginx Reverse Proxy: A Step-By-Step Tutorial

    CodeIgniter Remove index.php Using .htaccess

    Configuring the Nginx Reverse Proxy in Front of Apache

    View 2 Comments

    2 Comments

    1. Jeff on April 13, 2017 9:21 am

      Hi,

      I have a question here.

      From several sources on the Internet, they said that theses commands:

      BandWidth all 1000
      MaxConnection all 10

      will limit max bandwidth usage and number of connections to the our server/ VPS as a whole (not specifically to any 1 user’s IP address), but from other sources people said these lines would limit bandwidth usage and connections based on each user’s IP address. Which is true?

      For my purpose, I want to limit the bandwidth usage and max connections EACH USER can consume at the same time from my site (because I’m opening a file sharing service and I don’t want some user to open like 10 downloads simultaneously). I certainly don’t want to limit the max number of connections of ALL USERS TO MY SERVER, because there might be cases that more than 100 or 1000 users accessing my site at the same time – and that’s fine.

      Any thought?

      Thanks,
      Jeff.

      Reply
    2. TECHdire on July 8, 2016 6:25 am

      Thank you for sharing this info…I tried this on my server and its working fine 🙂

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • What is the /etc/mtab File in Linux
    • The “Hello World” Challenge: Printing in 20 Different Programming Languages
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.