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?
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
The form ofmeans 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.