Home >Operation and Maintenance >Linux Operation and Maintenance >How to limit concurrent connections and download speed in Linux apache

How to limit concurrent connections and download speed in Linux apache

王林
王林forward
2023-05-12 10:49:201632browse

mod_limitipconn, this is an unofficial module of Apache, which controls concurrent connections based on the same source IP, bw_mod, which can limit bandwidth based on the source IP, they are both third-party modules of Apache.

1. Download:

wget

wget

2. Installation

#tar -zxvf mod_limitipconn-0.22.tar.gz
#cd mod_limitipconn-0.22
#vi makefile
Modify: apxs = “/usr/local/apache2/bin/apxs” # Here is your own apache apxs path, load the 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

Use vi to open the apache configuration file httpd.conf

and find the following two lines:

loadmodule limitipconn_module modules/mod_limitipconn.so


loadmodule bw_module     modules/mod_bw.so

3. Configuration


 < location /home/bo@jb51.net/attachments/month _*> #Path to be controlled
maxconnperip 3 #Number of threads to limit
noiplimit index.htm #No restrictions on this file
< ;/location>

Add below the virtual host configuration file:

bandwidthmodule on
forcebandwidthmodule on
bandwidth all 10000 #speed limit 10k
minbandwidth all -1


The configuration parameter description is as follows:
a. bandwidthmodule on|off

//Whether to enable the bandwidth limitation function of mod_bw.

b. bandwidth [from] [bytes/s]

Set the maximum bandwidth of the specified client, 0 means no limit

bandwidth u:[user-agent] [bytes /s]

c. minbandwidth [from] [bytes/s]

Set the minimum value of the specified client bandwidth. If it is 0, it means that the maximum bandwidth of each client is 256bytes/s. -1 represents the maximum value of bandwith

d. largefilelimit [type] [minimum size] [bytes/s]

Set the maximum bandwidth for accessing a certain file exceeding a specific size, file type The size unit is kbytes

e. maxconnection [from] [max]

Set the maximum number of concurrent connections for the specified client

f. forcebandwidthmodule [on|off]

The default bw module will apply to all requests, on can set the filtering type

Regarding from, that is, the client source can be divided into the following situations:

ip specifies a single host

192.168.1.22

Specify the network segment

192.168.1.0/24 or

192.168.1.0/255.255.255.0

Domain name single host

client1.jb51.net

Domain name specified range

.jb51.net

All clients

all

The above configuration can be configured for all clients or a certain virtual host

Example 1:

bandwidthmodule on

bandwidth all 307200

bandwidth 192.168.1.2 102400

bandwidth “u:^mozilla/5(.*)” 102400

bandwidth “u:wget” 204800

forcebandwidthmodule on

largefilelimit .avi 600 204800

maxconnection all 100

maxconnnection 192.168.1.2 5

The above configuration meaning:

Enable mod_bw, and limit all file types.

The maximum bandwidth of all clients is 300k, and the maximum concurrent connections are 100

The maximum bandwidth of 192.168.1.2 is 100k, and the maximum concurrent connections is 5

The maximum bandwidth of the client using firefox is 100k

The maximum bandwidth of the client using wget is 200k

The maximum bandwidth of the avi format file exceeding 600k is 200kbyte/s

Example 2:

bandwidthmodule on

forcebandwidthmodule on

largefilelimit .avi 1 20000

largefilelimit .mpg 1 20000

servername

This instance limits the virtual host. The specified The maximum bandwidth of file types avi and mpg is 20k, and forcebandwidthmodule on is required.

Example 3:

bandwidthmodule on

addoutputfilterbytype mod_bw text/html text/plain

bandwidth all 5000

servername

The above is the detailed content of How to limit concurrent connections and download speed in Linux apache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete