nginx - Using ngx_http_limit_conn_module according to the tutorial, the number of concurrent connections of the virtual host cannot be limited
ringa_lee
ringa_lee 2017-05-16 17:14:08
0
3
731

I follow http://www.jb51.net/article/7... to configure the nginx.conf file to limit the number of concurrent connections to the virtual host. The following is the main content in nginx.conf.

http {

limit_conn_zone $server_name zone=perserver:10m;
include       mime.types;
default_type  application/octet-stream;

sendfile        on;
keepalive_timeout  65;

server {
    listen       54321;
    server_name  localhost;
    limit_conn perserver 100;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location / {
        root   html;
        index  index.html index.htm;
    }        
    location /status {
        stub_status on;
        access_log off;
    }
}
}


After the configuration is completed, reload the configuration file and use apache's ab tool to perform a stress test on 192.168.3.161:54321/index.html. The stress test code is as follows:
/usr/bin/ab -c 2000 -n 100000 http://192.168.3.161:54321/in...

对网站加压时,利用浏览器访问192.168.3.161:54321/status观察并发连接数,发现Active connections依然大于100,如下图所示。

Where is the problem with my configuration?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
洪涛

Changed my thinking.
The limit code written before is: limit_conn_zone $server_name zone=perserver:10m;
Using nginx’s built-in $server_name variable, it cannot successfully limit the number of concurrent connections.
I changed to: limit_conn_zone $server_port zone=perserver:10m;
Successfully limited the number of concurrent connections on a certain port

習慣沉默

You can use

limit_conn_zone $binary_remote_addr zone=perserver:10M; 
The form of

$binary_remote_addr

means using the user’s IP address, using $binary_remote_addr as the Key, and the IP address has a restrictive meaning. The $server_name you wrote above is not suitable as a criterion for judging the number of user connections

伊谢尔伦

Because this module is executed in the PREACCESS stage, it must have occurred in the http request processing stage after the tcp connection is established. The Active connections value above should refer to the number of concurrent tcp connections. Even if the number of concurrency is exceeded and 503 is returned, this is based on a successful TCP connection.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template