1. 限制单个 IP 的并发连接数
....
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
limit_conn_zone $binary_remote_addr zone=addr:10m; # 使用于设置共享内存区域,addr 是共享内存区域的名称,10m 表示共享内存区域的大小
server {
listen 80;
server_name www.abc.com;
location / {
root html/www;
index index.html index.htm;
limit_conn addr 1; # 限制单个IP的并发连接数为1
}
}
}
2. 限制虚拟主机总连接数
....
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
limit_conn_zone $server_name zone=perserver:10m;
server {
listen 80;
server_name www.abc.com;
location / {
root html/www;
index index.html index.htm;
limit_conn perserver 2; # 设置虚拟主机连接数为2
}
}
}