nginx 限速

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
http {
limit_conn_zone $binary_remote_address zone=perip:10m
...
server {
...
location /download/ {
# 限制每个IP只能建立一个连接
limit_conn perip 1;
# 当请求的流量超500KB后进行限速
limit_rate_after 500k;
# 限速 50KB/s
limit_rate 50k;
}
}
}

是对每个连接限速50k。这里是对连接限速,而不是对IP限速!如果一个IP允许两个并发连接,那么这个IP就是限速limit_rate * 2