How does apache limit concurrent connections and download speeds under Linux
- 2020-05-10 23:18:19
- OfStack
mod_limitipconn, this is an unofficial module of Apache, which controls concurrent connection with a source, IP, and Bw_mod, which limits bandwidth according to the source, IP, which is the third module of apache.
1. Download:
wget http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz
wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz
2. Install
#tar -zxvf mod_limitipconn-0.22.tar.gz
#cd mod_limitipconn-0.22
#vi Makefile
Modification: apxs = "/ usr local/apache2 / bin/apxs" # here is his apache apxs path, load module
or
# / usr local/apache2 bin/apxs - i - c - a mod_limitipconn. c to load the module
#make
#make install
#tar -xvf mod_bw-0.7.tgz
#cd mod_bw
#/usr/local/apache2/bin/apxs -i -c -a /home/kenami/mod_bw/mod_bw.c
Now open the httpd.conf configuration file for apache with vi
The following two lines are found:
LoadModule limitipconn_module modules/mod_limitipconn.so
LoadModule bw_module modules/mod_bw.so
Configuration of 3.
<
IfModule mod_limitipconn.c
>
<
Location /home/bo@ofstack.com/attachments/month _*
>
Need to control the path
MaxConnPerIP 3 # limit the number of threads
NoIPLimit index.htm # does not restrict this file
<
/Location
>
<
/IfModule
>
Add the following to the virtual host profile:
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 10000 # speed limit 10K
MinBandwidth all -1
Configuration parameters are described as follows:
a. BandWidthModule On|Off
// whether to turn on the bandwidth limiting function of mod_bw.
b. BandWidth [From] [bytes/s]
The setting specifies the maximum client bandwidth, with 0 being unlimited
BandWidth u:[User-Agent] [bytes/s]
c. MinBandWidth [From] [bytes/s]
sets the minimum value of the specified client bandwidth, with a value of 0 representing a maximum of 256bytes/s per client bandwidth, and a value of -1 representing a maximum of BandWith
d. LargeFileLimit [Type] [Minimum Size] [bytes/s]
sets the maximum bandwidth to access a certain file beyond a particular size. The file type size unit is kbytes
e. MaxConnection [From] [Max]
The setting specifies the maximum number of concurrent connections for the client
f. ForceBandWidthModule [On|Off]
default bw module will apply all requests, On can set the filter type
About From, the client source can be divided into the following situations:
IP specifies single 1 host
192.168.1.22
The specified network segment
192.168.1.0/24 or
192.168.1.0/255.255.255.0
Domain list 1 hosts
Client1.ofstack.com
Domain name specified range
.ofstack.com
All clients
all
The above configuration can be configured either for all clients or for a virtual host
Example 1:
BandWidthModule On
BandWidth all 307200
BandWidth 192.168.1.2 102400
BandWidth u: ^ Mozilla / 5 (. *) "in 102400
BandWidth "u: wget" 204800
ForceBandWidthModule On
LargeFileLimit .avi 600 204800
MaxConnection all 100
MaxConnnection 192.168.1.2 5
The above configuration meaning:
Turn on mod_bw and restrict all file types
All clients have a maximum bandwidth of 300k and a maximum concurrent connection of 100
192.168.1.2 has a maximum bandwidth of 100k and a maximum concurrent connection of 5
The maximum bandwidth of a client using FireFox is 100k
The maximum bandwidth of a client using wget is 200k
For files in avi format over 600k, the maximum bandwidth is 200kbyte/s
Example 2:
< Virtualhost * >
BandwidthModule On
ForceBandWidthModule On
LargeFileLimit .avi 1 20000
LargeFileLimit .mpg 1 20000
Servername www.ofstack.com
< /Virtualhost >
This example restricts the virtual host to a maximum bandwidth of 20K for the specified file types avi and mpg, and ForceBandWidthModule On must have.
Example 3:
< Virtualhost * >
BandwidthModule On
AddOutputFilterByType MOD_BW text/html text/plain
Bandwidth all 5000
Servername www.ofstack.com
< /Virtualhost >