时间:2023-06-02 16:16:41 来源: 人气:
1,配置nginx.conf,代码如下 http{ ............. limit_zone one $binary_remote_addr 10m; //我记得默认配置就有,只不过是注释掉了,如果没有加一下 .............. server{ ................. location { ......... limit_conn one 20; //连接数限制 limit_rate 500k; //带宽限制 ........ } ................. } ............. },[root@localhost nginx]# /etc/init.d/nginx reload //重新加载 ,2,测试限制ip连接数,代码如下 [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 //这样的数据有很多,最好加个more或者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" - ,..............................................................................................,通过以上测试,可以得出限制ip连接数是没有问题的,但是限制带宽看不出来,说实话这个不好测试,所以就没测试了,利用apache限制IP并发数和下载流量控制,安装mod_limitipconn限制IP连接数,1,下载地址:http://dominia.org/djao/limitipconn2.html,2,安装:[root@BlackGhost mod_limitipconn-0.22]# /usr/local/apache2/bin/apxs -c -i mod_limitipconn.c,3,配置如下vi httpd.conf,代码如下 ExtendedStatus On LoadModule limitipconn_module modules/mod_limitipconn.so