Tuesday, December 4, 2012

How to limit the connection per ip in the server?

We can limit the number of connections per IP on server by installing mod_limitipconn for apache.This will helpfull to control the load in server also.

# cd /usr/local/src

Now, we need to grab the file (this is the latest version as of this post):

# wget http://dominia.org/djao/limit/mod_limitipconn-0.23.tar.bz2

# tar xjvf mod_limitipconn-0.23.tar.bz2

# cd mod_limitipconn-0.23

# apxs -i -a -c mod_limitipconn.c

# cd /etc/httpd/conf

Create an configuraton file for mod_limit connection and included it in httpd.conf file and restart the httpd service

# vi mod_limit.conf

ExtendedStatus On
<IfModule mod_limitipconn.c>
<Location />
MaxConnPerIP 2
</Location>
</IfModule>


Example configuration:

# This command is always needed
ExtendedStatus On

# Only needed if the module is compiled as a DSO
LoadModule limitipconn_module lib/apache/mod_limitipconn.so

<IfModule mod_limitipconn.c>

# Set a server-wide limit of 10 simultaneous downloads per IP,
# no matter what.
MaxConnPerIP 10
<Location /somewhere>
# This section affects all files under http://your.server/somewhere
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>

<Directory /home/*/public_html>
# This section affects all files under /home/*/public_html
MaxConnPerIP 1
# In this case, all MIME types other than audio/mpeg and video*
# are exempt from the limit check
OnlyIPLimit audio/mpeg video
</Directory>
</IfModule>

No comments:

Post a Comment