Categories
Apache Internet

Apache2 – mod_bw – przycinanie ruchu

W erze udostępniania wszystkiego i wszystkim przez użyszkodników postanowiłem trochę poograniczać ruch wychodzący z Apache.
Okazało się że bardzo łatwo można to zrobić przy wykorzystaniu modułu mod_bw dla Apache2.

Za dystrybucję bazową posłużył Debian Lenny.

Instalacja z paczek:
apt-get install libapache2-mod-bw && /etc/init.d/apache2 restart

Aktywacja modułu:
a2enmod bw && /etc/init.d/apache2 restart

Ustawienie polityki dla przykładowej domeny:
#ustawiam 100KiB/sek dla stronki www.mojasuperfajnadomena.pl
<Virtualhost *>
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 102400
MinBandwidth all -1
Servername www.mojasuperfajnadomena.pl
</Virtualhost>

Dodatkowo można ograniczyć transfery dla poszczególnych typów plików:
LargeFileLimit .avi 1 200000
LargeFileLimit .mpg 1 200000
LargeFileLimit .exe 1 200000
LargeFileLimit .rar 1 200000
LargeFileLimit .zip 1 200000

…wszystko zależy od fantazji administratora 😉

Poniżej kilka przykładów z dokumentacji:

Limit every user to a max of 10Kb/s on a vhost :


BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10240
MinBandwidth all -1
Servername www.example.com

Limit al internal users (lan) to 1000 kb/s with a minimum of 50kb/s , and
files greater than 500kb to 50kb/s.


BandwidthModule On
ForceBandWidthModule On
Bandwidth all 1024000
MinBandwidth all 50000
LargeFileLimit * 500 50000
Servername www.example.com

Limit avi and mpg extensions to 20kb/s.


BandwidthModule On
ForceBandWidthModule On
LargeFileLimit .avi 1 20000
LargeFileLimit .mpg 1 20000
Servername www.example.com

Using it the “right” way, with output filter by mime type (for text)
to 5kb/s:


BandwidthModule On
AddOutputFilterByType MOD_BW text/html text/plain
Bandwidth all 5000
Servername www.example.com

Więcej info na stronie projektu http://bwmod.sourceforge.net/.

Powodzenia w ograniczaniu.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.