Apache uses mod_bandwidth module to limit download speed examples

Source: Internet
Author: User
Tags documentation ftp time interval

Now the server is generally 100M optical access, but this is not what we usually say download speed, such as asking the network server bandwidth of 1Mbps, I see 1 m download speed, in fact, only 128kb/s, this speed if there are 100 people access to ask the net, the server basic card.

Based on the above introduction, we may need to download the server speed limit, Apache has mod_bandwidth module can achieve this function, download the address: ftp://ftp.cohprog.com/pub/apache/module/. SourceForge Address: http://bwmod.sourceforge.net/

Mod_bandwidth is the Apache server to limit the bandwidth consumption of the module, you can control the number of concurrent IP, can also control the download flow, you can also control the flow of a directory.

Configure Mod_bandwidth

modifying httpd.conf files

Add the following content

LoadModule Bandwidth_module libexec/apache/mod_bandwidth.so
Addmodule mod_bandwidth.c

Note: These two lines must be added to the front of the corresponding area, allowing the module to run at the lowest priority level.

Add the following content

Bandwidthdatadir "/tmp/apachebw/"
Bandwidthmodule on
Do not limit the download speed of users within the LAN

Bandwidth 192.168.0 0
Limit the download speed of other users to 8192 bytes per second

Bandwidth All 8192
Modify the other bars in the way above

Configuration parameters

After extracting bandwidth compressed files, there is a mod_bw.txt with detailed instructions and examples, the following is part of the parameter description:

Bandwidthdatadir

Format: Bandwidthdatadir
Default: "/TMP/APACHEBW"
Context: Server Config

Sets the directory where Mod_bandwidth saves run-time data. You need to create the./master and./link Two subdirectories in this directory, and set the permission to 777.

Note: Some systems regularly clean the/tmp directory, so it is best to set Bandwidthdatadir to other locations on these systems.

Bandwidthmodule

Format: Bandwidthmodule
Default: Off
Context: Per server config

Allow or disable modules.

Bandwidthpulse

Format: Bandwidthpulse
Default: 1000
Context: Per server config

Changes the time interval for calculating bandwidth by default of 1000 milliseconds (1 seconds). Lower intervals allow for more precise bandwidth control, but consume more CPU time and vice versa.

Note: Please refer to the Mod_bandwidth documentation for detailed instructions for this option.

Bandwidth

Format: Bandwidth
Default: None
Context: Per directory,. htaccess

Limit the rate of file downloads in this directory.

domain specifies which domains from which the connection is affected by this setting.
IP Specifies the connection from which IP address (or IP segment) is affected.
All connections are affected.
Example:

# Connections from dualface.com do not limit download speed
Bandwidth dualface.com 0
# Connections from 192.168.0.0/16 (or 192.168.0) network segments do not limit download speed
Bandwidth 192.168.0.0/16 0
# Other connection limit download speed of 1024 bytes per second
Bandwidth all 1024
# Higher precedence in front
Largefilelimit

Format: Largefilelimit
Default: None
Context: Per directory,. htaccess

The rate at which the download is used for files that exceed the specified size. If the rate is set to 0, the speed is not limited, but the download speed is still affected by the bandwidth setting. If set to 1, it is not affected at all.

By setting different file sizes and rates, you can set the download speed of files in different size ranges.

Example:

# file size is greater than 200,000 bytes of files, download rate is 3072 bytes per second
Largefilelimit 200 3072
Largefilelimit 1024 2048
Maxconnection

Format: maxconnection
Default: 0 (No limit)
Context: Per directory,. htaccess

Rejects the new connection when the specified number of connections is exceeded.

Minbandwidth

Format: Minbandwidth
Default: All 256
Context: Per directory,. htaccess

Set the minimum bandwidth, which defaults to 256 bytes per second. The rate set according to bandwidth and Largefilelimit. Mod_bandwidth the number of connections allowed in the accounting calculation. For example, bandwidth is 4096 bytes, and Minbandwidth is 1024 bytes, the maximum number of concurrent connections is 4.

Note: Please refer to the Mod_bandwidth documentation for detailed instructions for this option.

ErrorDocument

The following is the configuration error page, if not set, Apache will complain, on the root of the 404 almost, the page is very ugly.

ErrorDocument 510/exceed_speed.html
Bandwidtherror 510

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.