ubuntu apache2 流量限制模块
mod-bw is an Apache 2 module provided to solve the problem of limiting users’ and virtual hosts’ bandwidth usage. The current versions can set virtual hosts’ and users’ bandwidth quotas, maximal download speed, requests-per-second speed and the maximal number of simultaneous IP connections.
mod-bw Features:
* Lightweight bandwidth limiting module for Apache2
* per-user bandwidth limiting
* per-virtual host bandwidth limiting
* per-destination bandwidth limiting
Limiting:
* Bandwidth total usage (bandwidth quota)
* Maximal download speed (bandwidth throttling)
* Maximal requests-per-second speed
* Maximal simultaneous IP connections
* Support for virtual hosts
* Support for defined users
Installing mod-bw:
Open the terminal and type following command to install mod-bw
1
|
apt-get install libapache2-mod-bw |
Now enable the module by using the a2enmod command (from terminal):
1
|
sudo a2enmod bw |
Below example is showing how to place the bandwidth limit for a given virtual hosts:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<VirtualHost *:8080> ServerName www.abc.com ServerAlias www.abc.com DocumentRoot /var/www/abc # Turn bandwidth limitation on BandwidthModule On # force limitation on every request ForceBandWidthModule On # limit to 500kB/s Bandwidth all 504800 # Setup custom error message ErrorDocument 510 /errors/maxconexceeded .html BandWidthError 510 # Limit avi and mpg extensions to 20kb/s. LargeFileLimit .avi 1 20000 LargeFileLimit .mpg 1 20000 < /VirtualHost >
|