ngx_http_limit_conn_module 和 ngx_http_limit_req_module是nginx自带的频率限制模块
运用这两个模块,可以简单限制单IP的访问频率,防止单用户耗尽系统资源
nginx也自带限速模块, 限制用户下载速度
以下配置可以放在 http, server, location 自由选择放置位置
################limit 限制###################
map $http_x_forwarded_for $clientRealIp {
"" $remote_addr;
~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr;
}
####用户速度限制
#limit_rate_after 10m;
#limit_rate 500K;
## 限制原始用户 IP 地址TCP连接数
limit_conn_zone $clientRealIp zone=TotalConnLimitZone:20m ;
limit_conn TotalConnLimitZone 20;
limit_conn_status 444;
#limit_conn_log_level notice;
## 限制原始用户 IP 地址请求数
limit_req_zone $clientRealIp zone=ConnLimitZone:20m rate=1r/s;
limit_req zone=ConnLimitZone burst=10 nodelay ; #如果开启此条规则,burst=10的限制将会在nginx全局生效
limit_req_status 444;
#limit_req_log_level notice;
具体请查看官方文档
http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html
http://nginx.org/en/docs/http/ngx_http_limit_req_module.html

此处评论已关闭