Limit IP connection count, IP concurrency, and traffic control in APACHE

Source: Internet
Author: User
Tags bz2

 

Use the Limit module to Limit the number of IP connections

System version: centos6.3

APACHE version: apache2.42 (compilation and installation)

1. Configure the Limit module

# Wget http://dominia.org/djao/limit/mod_limitipconn-0.24.tar.bz2

Installation:

# Tar jxvf mod_limitipconn-0.24.tar.bz2

# Cd mod_limitipconn-0.24

# Vi Makefile

Find the row APXS and change it

APXS =/usr/local/apache2/bin/apxs

# Make & make install

Example of global variables:

<IfModule mod_limitipconn.c>

<Location/> # all virtual hosts/Directory

MaxConnPerIP 3 # each IP address only allows three concurrent connections

NoIPLimit image/* # no IP address limit on images

</Location>

<Location/mp3> # all hosts/mp3 directories

MaxConnPerIP 1 # each IP allows only one connection request

OnlyIPLimit audio/mpeg video # this restriction only applies to video and audio files.

</Location>

</IfModule>

# Vi/usr/local/apache2/conf/httpd. conf

--------------------

 

ExtendedStatus On

LoadModule limitipconn_module modules/mod_limitipconn.so

<IfModule mod_limitipconn.c>

<Location/>

MaxConnPerIP 6

NoIPLimit image /*

</Location>

</IfModule>

-------------------

 

2. Configure webbench to perform a stress test on the website:

# Wget http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz

# Tar zxvf webbench-1.5.tar.gz

# Cd webbench-1.5

# Make & make install

 

3. Usage:

Webbench-c 500-t 30 http: // 127.0.0.1/

Parameter description:-c indicates the number of concurrencies, and-t indicates the time (seconds)

 

4. Test result example:

Webbench-Simple Web Benchmark 1.5

Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

 

Benchmarking: GET http: // 127.0.0.1/

500 clients, running 30 sec.

Speed = 3230 pages/min, 11614212 bytes/sec.

Requests: 1615 susceed, 0 failed.


Apache limits the number of connections of an IP address

The biggest advantage of Apache is that it is a modular program, and the corresponding functional modules can be developed independently without any features. However

This can be added to Apache. A customer in the project has many resources on the platform, and many people use multi-thread download tools to download the resources.

The server load is very high, so I thought of limiting the number of IP connections. If Apache is 1.x

Http://dominia.org/djao/limitipconn.html here Download the corresponding Linux version (not for windows), if yes

2. For version x, download linux's windows from http://dominia.org/djao/limitipconn2.html.

On Linux, the installation method is clearly written. For windows

Place mod_limitipconn.dll in the modules Directory of the Apache installation directory;
Then modify the Apache configuration file httpd. conf, which is the same in both Linux and Windows. If it is 2.0, first find

LoadModule status_module modules/mod_status.so in httpd. conf, remove the # above this sentence, and then add

The following content:

ExtendedStatus On

LoadModule limitipconn_module modulesmod_limitipconn.dll
<IfModule mod_limitipconn.c>
<Location/resource>
MaxConnPerIP 3
# Exempting images from the connection limit is often a good
# Idea if your web page has lots of inline images, since these
# Pages often generate a flurry of concurrent image requests
NoIPLimit image /*
</Location>
</IfModule>

In/resource is the Directory of the specified IP address, and MaxConnPerIP is the number of concurrent connections for each IP address, NoIPLimit

Image/* is a directory that is not limited by resource.


Apache limits IP concurrency and traffic control


Use the mod_limitipconn module to limit the number of concurrent IP connections
Installation:

Wget http://dominia.org/djao/limit/mod_limitipconn-0.24.tar.bz2
Tar jxvf mod_limitipconn-0.24.tar.bz2
Cd mod_limitipconn-0.24
/Usr/local/apache2/bin/apxs-c-I mod_limitipconn.c

Edit httpd. conf

ExtendedStatus On
LoadModule limitipconn_module modules/mod_limitipconn.so
 
<IfModule mod_limitipconn.c>
<Location/> # corresponding root directory
MaxConnPerIP 5 # maximum concurrency of 5
NoIPLimit image/* # no restrictions on images
</Location>
<Location/test> # restrict the test directory under the root directory
MaxConnPerIP 2 # maximum concurrency of 2
</Location>
</IfModule>

To limit the number of concurrent ip connections to a VM, modify the extra/httpd-vhost.conf to set the IfModule

Copy the mod_limitipconn.c segment to Virtualhost.

Test:
The test is simple. Reduce the maximum number of connections by visiting the page in a browser and press F5 to refresh the page.

The 503 error is displayed.

Use the mod_bandwidth module to limit bandwidth
Mod_bandwidth can be used to control the number of concurrent IP addresses, download traffic, or traffic in a directory.

Control.
Installation:

Wget http://bwmod.sourceforge.net/files/mod_bw-0.7.tgz
Tar zxvf mod_bw-0.7.tgz
Cd mod_bw
/Usr/local/apache2/bin/apxs-c-I mod_b1_c
Edit the httpd. conf configuration file:

LoadModule bw_module modules/mod_bw.so
 
<VirtualHost *: 80>
ServerName vhost1.cszhi.com
DocumentRoot/var/www/vhost1
BandwidthModule On
ForceBandWidthModule On
Bandwidth all 1024000
MinBandwidth all 50000 # The maximum speed of each client is 50 kB.
LargeFileLimit * 500 50000
MaxConnection all 6
</VirtualHost>
The following is an example to describe the mod_b1_txt file in the source code package:

BandWidth localhost 0 # no speed limit on localhost
BandWidth 192.168.1.5 102400 # The speed limit for 192.168.1.5 is KB
BandWidth "u: ^ Mozilla (. *)" 10240 # speed of 10 kB with mozilla
BandWidth "u: wget" 102400 # if wget is used, the download speed is 10 kB.
MinBandWidth all-1 # ensure the maximum speed of each client is 10 KB
LargeFileLimit. jpg 100 10240 # jpg file exceeds KB, with a speed limit of 10 KB
# The following 510 is quite good. If it is not set, apache will report an error on its own, and it will report a 404 error. The page is very ugly.
ErrorDocument 510/exceed_speed.html
BandWidthError 1, 510
MaxConnection all 10 # the maximum number of connections to all ip addresses is 10
MaxConnection 192.168.1.5 5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.