Apache2 - Mod_bw v0.7
Author : Ivan Barrera A. (Bruce)
HomePage : Http://Ivn.cl/apache & http://bwmod.sf.net
Release Date : 01-09-2005
Status : Functional. Tested under medium and heavy load.
License : Licensed under the Apache Software License v2.0
It must be included as LICENSE in this package.
Platform : Linux/x86 (Tested with Fedora Core 4, Suse, etc)
FreeBSD/x86 (Tested on 5.2)
MacOS X/Ppc x86 (Tested on both platforms)
Solaris 8/sparc (Some notes on compile)
Microsoft Windows (Win XP, Win2003. Others should work)
Notes : This is a stable version of mod_bw. It works fine with
almost any MPM (tested with WinNT/prefork/Worker MPM).
Limitations : This mod doesn't know how fast is the client really
downloading a file, so it just divides the bw assigned
between the users.
MaxConnections works only for the given scope. (i.e , all
will limit maxconnections from all,not per ip or user)
------------------------------------------------------------------------------
Contents :
1 .- Notices
1.1 - Summer Of Code Program
1.2 - ChangeLog and TODO
2 .- Installing
2.1 - Windows
2.2 - Linux
3 .- Getting it to Work, Directives
3.1 - BandWidthModule
3.2 - ForceBandWidthModule
3.3 - BandWidth
3.4 - MinBandWidth
3.5 - LargeFileLimit
3.6 - BandWidthPacket
3.7 - BandWidthError
3.8 - MaxConnection
4 .- Examples
4.1 - Misc Examples
5 .- FAQ
------------------------------------------------------------------------------
1.- Notices
1.1 - Summer Of Code Program :
Google did Summer Of Code 2005 program, to motivate the development of
open source software. Many students around the world signed on the program
in differents areas/projects.
Mine has to do with Bandwidth limiting in current Apache webserver. The
main idea behind the program, is to incentivate the development of quality
open source program.
Mod Bw, participated, and completed the program.
------------------------------------------------------------------------------
1.2 - ChangeLog & TODO :
This has been moved to the files ChangeLog and TODO. Available on the
packages and CVS at SourceForge.
------------------------------------------------------------------------------
2.- How To Install :
2.1 - Windows
In Windows, you have to download the binary dll from the site (or compile
one yourself) that matches your apache version, and Install it under modules
on your apache tree. Then edit httpd.conf, and add the LoadModule sentence.
If there is no matching binary dll with your version of apache (the latest)
you can ask me to compile it for you. Post a message in the home site as a
feature request.
Example :
Download mod_bw-2.0.55.dll from the home site, to c:\apache2\modules
Edit httpd.conf, and add LoadModule bw_module modules/mod_bw-2.0.54.dll
Restart Apache.
2.2 - Linux
Well.. (under *nix) you *have* to compile it..
It might sound scary, but it's easy. There is an easy way, and the hard way.
If the easy way doesn't work for you, use the hard way.
REQUIREMENTS :
You will need apache2 headers in the include path. In redhat/suse or others
this mean apache-devel or httpd-devel installed.
You also need support for SHM in your OS. Usually you will have this.
- Easy Way :
For this to work, you MUST have apxs (or apxs2) installed. You might need
to use it full path (i.e. /usr/sbin/apxs .....). Well, you have to do this :
apxs -i -a -c mod_bw.c
or
apxs2 -i -a -c mod_bw.c
This will bring out some stuff... nothing to worry (unless you see error)
If it says ok, then you are ready. Restart apache (service apache restart on
redhat, mandrake, and others... apachectl restart .. rcapache2 restart or...
well, you should know)
Note On Solaris Users :
If you got problems compiling it on Solaris, remember to check you have
libgcc correctly installed, and the ld_library_path set up correctly.
I didnt, so i compiled this way :
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
apxs -i -a -c mod_bw.c -L/usr/local/lib -lgcc_s
And then started apache, and everything worked fine.
Note On SuSe Users :
You NEED to have installed apache2 header files (apache2-devel rpm).
Otherwise you'll get lots of include files error.
- Hard Way
If using the easy way, you turned to have some .o files.. you are almost
done... skip to the part of installing the module.
Back to the hard way..... you might notice that you dont have apxs,
dont know why (maybe the dog ate it). Well. try the following (and please
do it on a newly-fresh created directory for this purpose) :
(this does not necessarily work on all cases)
libtool --silent --mode=compile gcc -g -O2 -pthread -DLINUX=2 \
-D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE \
-I/usr/include/httpd \
-I/usr/include/apr-0 -Wall -g\
-prefer-pic -c mod_bw.c && touch mod_bw.slo
libtool --silent --mode=link gcc -g -O2 -pthread -DLINUX=2 \
-D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE \
-D_GNU_SOURCE -DAP_HAVE_DESIGNATED_INITIALIZER \
-I/usr/include/httpd \
-I/usr/include/apr-0 -Wall -g\
-export-dynamic -o mod_bw.la -rpath /usr/lib/httpd/modules \
-module -avoid-version mod_bw.lo
(this cleans some unneeded files)
rm -rf *.a *.la *.lo *.slo *.o *.loT
mv .libs/*.so .
rm -rf .libs
Note that you need to know where are your httpd and apr includes.
(dont ask me where they are.. you are supossed to know)
If this worked... we are good to install the module.
* Installing the module (hey.. this is part of the hard way)
Ok, either if the easy way didnt install the mod, or if you did the
hard way, now you must install the module by hand.
Is easy as copying the file (usually mod_bw.so) to the apache
modules directory (usually /etc/httpd/modules or
/usr/local/libexec/apache2/) and then adding the following line at
httpd.conf (better of if you add it at the last part of all LoadModule
sentences) :
LoadModule bw_module mod_bw.so
Please, take a look at the other LoadModule sentences. You may need
to add a path before the .so file.
(i.e LoadModule bw_module libexec/apache2/mod_bw.so)
If you didn't manage to get it installed, drop me a letter. But please
be sure you tried everything. Sometimes the simplest way, is the better.
------------------------------------------------------------------------------
3.- Getting it to Work :
Ok.. this is the most confusing part. (yeh, most of us think the installing
part is the hardest xD )
This mod, is able to limit bandwidth usage on every virtual host or
directory. htaccess files are not supported yet, cause i've been having some
serious segfaults when implementing it.
* Configuration Directives
*****************************************************************************
3.1 - BandWidthModule [On|Off]
You need to set this to On, for the mod to work.. By default, the mod is
disabled, and wont limit anything.
Example :
BandWidthModule On
3.2 - ForceBandWidthModule [On|Off]
By default, the mod wont catch every request.
If you enable it, every request will be processed by the mod.
Example :
(normal use)
AddOutputFilterByType MOD_BW text/html text/plain
(enabling Force)
ForceBandWidthModule On
3.3 - BandWidth [From] [bytes/s]
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 t