一、限制單個 IP 的併發連接數
[root@localhost ~]# cat /usr/local/nginx/conf/nginx.conf .... http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.abc.com; location / { root html/www; index index.html index.htm; } } }
二、限制虛擬主機總連接數
.... 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 } } }