Number of concurrent Apache connections and bandwidth control in Linux (1)

Source: Internet
Author: User

The stability, security, performance, and low price of Linux + Apache are gaining more and more market share. More and more friends are using Linux + Apache as website servers, while Apache is an http service, it is not easy to control over FTP, especially when the website provides software/music downloads via http, if each user enables multiple threads without bandwidth restrictions, it will soon reach the maximum number of http connections or cause network congestion, making many normal services of the website unable to run. However, Apache users have already developed mod_limitipconn and mod_bandwidth modules to control the number of concurrent http connections and the bandwidth available to users, the following describes how to use RedHat Linux 7.3 + Apache 1.3.7.

I. Use mod_limitipconn to limit the number of concurrent connections of Apache

Mod_limitipconn can control the number of concurrent connections of each IP address to a directory on the server at the same time. It is a very useful module and supports Apache 2. x module download, because I use Apache 1.3.7, so please use 2. A friend of Apache of Version x goes to the official website to check the specific usage method.

Mod_limitipconn for Apache 1.3x provides three installation methods: tar package, rpm installation file, and rpm source file. Since the rpm package can only be used in RedHat 7.x, and does not support proxy detection, therefore, we generally use the tar package installation method.

Log on to the server as an administrator, then run the wget http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz on the server to download the tar package of mod_limitipconn to the server, and then press run tar zxvf mod_limitipconn-0.04.tar.gz to decompress the tar package, the mod_limitipconn-0.04 directory is generated under the current directory, and then the cd mod_limitipconn-0.04 enters this directory, the next step is to use apxs to compile mod_limitipconn.c in the directory. At this time, we need to determine the directory where our Apache is installed and find out where the apxs command is.

By running the whereis apxs command, we can determine the path of the apxs command. For example, if my apxs command is/usr/sbin/apxs, then, enter/usr/sbin/apxs-c-I-a mod_limitipconn.c to compile mod_limitipconn.c. This command will automatically go to your Apache configuration file httpd. add the required information to the conf file and copy the generated mod_limitipconn.so module to the Module Directory of Apache. To check whether the command works properly, check the directory of your Apache module (my directory is/usr/lib/apache) to check whether the mod_limitipconn.so file is contained in the directory, if not, copy the files generated in the mod_limitipconn-0.04 directory here.

The httpd. conf generated by the command just now may have some errors. In my system, it places LoadModule limitipconn_module modules/modules between LoadModule python_module modules/mod_python.so, while AddModule modules are placed

AddModule mod_python.c

The mod_limitipconn module does not run properly. Therefore, move the two lines to the corresponding row that does not exist, and then confirm that the mod_status module has been loaded, the ExtendedStatus On line is added under mod_status. In this case, the mod_limitipconn module is installed. The next step is to set the number of concurrent connections for a directory.

Mod_limitipconn can impose different restrictions on global and virtual hosts. Its syntax structure is

# The restricted directory, which indicates the root directory of the host

MaxConnPerIP 3 # The number of concurrent connections per IP address is 3

NoIPLimit image/* # No IP address limit on Images

# The restricted directory, which indicates the/mp3 directory of the host.

MaxConnPerIP 1 # The number of concurrent connections per IP address is 1

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

When global restrictions are imposed, place the code in httpd. the conf file does not contain VirtualHost. If you want to restrict a virtual host, place it between and. You can change the Location and MaxConnPerIP to conveniently control the restricted directory and number of concurrent connections.

Finally, as long as you restart the Apache service, the limit on the number of concurrent connections takes effect.


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.