The
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.
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/secMaxConnection all 10 </Directory> </Virtualhost>
After making all required configurations restart apache service to take effect new chnages.
# service httpd restart
2 Comments
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.
Thank you for sharing this info…I tried this on my server and its working fine 🙂