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
}
}
}
作者簡介:
陳志珂(頭條號:強扭的瓜不好吃)公眾號“鉛筆學園”運維內容合作作者之一,目前就職於中國最大的安卓應用軟件公司,任高級工程師,現在公司任php開發工程師,python開發工程師,高級運維工程師。
鉛筆學園:IT資源分享|知識分享,做初級程序員的指明燈