Managing server resources efficiently is essential for maintaining performance and stability. If a particular domain or directory is consuming excessive bandwidth, you can control its usage using the mod_bw module in Apache.
The mod_bw (bandwidth module) allows administrators to restrict bandwidth usage and limit the number of simultaneous connections for specific virtual hosts (vhosts) or directories. This is especially useful in shared hosting environments where resource control is critical.
When to Use mod_bw
You can use mod_bw when:
- A domain is consuming high bandwidth
- Want to limit download speeds for files
- Need to restrict simultaneous connections
- Want better control over server resource usage
Steps to Install and Configure mod_bw
1. Check Apache Version
Run the following command to verify your Apache version:
/usr/local/apache/bin/httpd -v 2. Download the mod_bw Module
cd /usr/src
wget http://ivn.cl/files/source/mod_bw-0.92.tgz 3. Extract the Package
tar -zxf mod_bw-0.92.tgz
cd mod_bw 4. Review Configuration Instructions
cat mod_bw.txt | more 5. Install the Module
/usr/local/apache/bin/apxs -i -a -c mod_bw.c 6. Create Configuration File
cat mod_bw.txt | perl -pe 's:^:# :g' > /usr/local/apache/conf/mod_bw.conf 7. Verify Module Configuration
Edit the file:
/usr/local/apache/conf/mod_bw.conf Ensure the following entries are enabled:
LoadModule bw_module modules/mod_bw.so<Location /modbw>
Order deny,allow
Deny from all
Allow from 127.0.0.1
SetHandler modbw-handler
</Location> 8. Update Apache Main Configuration
Open:
/usr/local/apache/conf/httpd.conf Make sure these lines are present and enabled:
LoadModule bwlimited_module modules/mod_bwlimited.so
Include "/usr/local/apache/conf/mod_bw.conf" 9. Add Configuration to Domain (vhost)
In the Apache configuration, include mod_bw settings for the specific domain:
Include "/usr/local/apache/conf/userdata/std/2/username/domainname.com/mod_bw.conf" 10. Configure Bandwidth Limits
Create or edit the file:
/usr/local/apache/conf/userdata/std/2/username/domainname.com/mod_bw.conf Add the following configuration:
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 100000
MinBandwidth all -1
Explanation:
Bandwidth all 100000→ Limits bandwidth to ~100 KB/sMinBandwidth all -1→ No minimum bandwidth restriction
11. Restart Apache
Apply the changes by restarting Apache:
/etc/init.d/httpd graceful Conclusion
Using mod_bw in Apache is an effective way to control bandwidth usage and limit connections for specific domains or directories. By implementing these configurations, you can prevent resource abuse, improve server performance, and ensure fair usage across hosted applications.
For optimal results, always monitor your server after applying limits and adjust the configuration based on your requirements.
If you require help, contact SupportPRO
Partner with SupportPRO for 24/7 proactive cloud support that keeps your business secure, scalable, and ahead of the curve.
