1. Configure nginx. conf
The code is as follows: |
Copy code |
Http { ............. Limit_zone one $ binary_remote_addr 10 m; // I remember the default configuration, but it is commented out. If it is not added .............. Server { ................. Location { ......... Limit_conn one 20; // connection limit Limit_rate 500 k; // bandwidth limit ........ } ................. } ............. } [Root @ localhost nginx] #/etc/init. d/nginx reload // reload |
2. Test the ip address connection limit.
The code is as follows: |
Copy code |
[Root @ localhost nginx] # webbench-c 100-t 2 http: // 127.0.0.1/index. php Webbench-Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http: // 127.0.0.1/index. php 100 clients, running 2 sec. Speed = 429959 pages/min, 2758544 bytes/sec. Requests: 14332 susceed, 0 failed. [Root @ localhost nginx] # cat/var/log/nginx/access. log | grep 503 | more // There is a lot of such data, it is best to add more or less 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- 127.0.0.1--[25/Apr/2012: 17: 52: 21 + 0800] "GET/index. php HTTP/1.0" 503 213 "-" "WebBench 1.5 "- |
........................................ ........................................ ..............
Through the above tests, it can be concluded that there is no problem in limiting the number of ip connections, but the limited bandwidth cannot be seen. To be honest, this is not a good test, so it is not tested.
Use apache to limit IP concurrency and download traffic control
Install mod_limitipconn to limit the number of IP connections
1, download address: http://dominia.org/djao/limitipconn2.html
2, install: [root @ BlackGhost mod_limitipconn-0.22] #/usr/local/apache2/bin/apxs-c-I mod_limitipconn.c
3. Configure the following vi httpd. conf:
The code is as follows: |
Copy code |
ExtendedStatus On LoadModule limitipconn_module modules/mod_limitipconn.so <IfModule mod_limitipconn.c> <Location/> # corresponding root directory MaxConnPerIP 6 # maximum concurrency NoIPLimit image/* # no restrictions on images </Location> <Location/download> # download MaxConnPerIP 1 # MaxConnPerIP 1 </Location> </IfModule> |
Note: After mod_limitipconn-0.22.tar.gz is decompressed, there is a README configuration in the file, which can be changed based on your needs. If not, you can check it online, there are so many people using apache, I think someone else has encountered your problem, and I can check it out. If you want to place it in the VM for maximum concurrency control, you can modify the extra/httpd-vhost.conf to copy the <IfModule mod_limitipconn.c> to <Virtualhost>.
3. Install mod_bandwidth
Mod_bandwidth can be used to control the number of concurrent IP addresses, download traffic, or traffic in a directory.
1, download address: http://bwmod.sourceforge.net/
2. Install [root @ BlackGhost mod_bw] #/usr/local/apache2/bin/apxs-c-I mod_b1_c
3. Configure vi httpd. conf with LoadModule bw_module modules/mod_b1_so
Then open the vi httpd-vhosts.conf
The code is as follows: |
Copy code |
Listen 10004. Namevirtualhost*: 10004 <VirtualHost *: 10004> DocumentRoot "/home/zhangy/www/test" ServerName *: 10004. BandwidthModule On ForceBandWidthModule On Bandwidth all 1024000 MinBandwidth all 50000 LargeFileLimit * 500 50000 MaxConnection all 6 ErrorLog "/home/zhangy/apache/www.test.com-error. log" CustomLog "/home/zhangy/apache/www.test.com-error. log" common </VirtualHost> |
After the compressed bandwidth' file is decompressed, a mod_b1_txt file contains detailed instructions and examples. The following describes some parameters:
1. BandWidth localhost 0 # no speed limit on localhost
2, BandWidth 192.168.1.5 102400 # The speed limit for 192.168.1.5 is KB
3, BandWidth "u: ^ Mozilla (. *)" 10240 # speed of 10 kB with mozilla
4, BandWidth "u: wget" 102400 # if wget is used, the download speed is 10 kB.
5. MinBandWidth all-1 # ensure the maximum speed of each client is 10 KB
6. LargeFileLimit. jpg 100 10240 # The jpg file exceeds KB and is limited to 10 kB.
7, # 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
8, MaxConnection all 10 # the maximum number of connections to all ip addresses is 10
9. MaxConnection 192.168.1.5 5 # the maximum number of connections to 192.168.1.5 is 5.