limit:限制,rep:请求
启动请求限制频率
ngx_http_limit_req_module
#测试命令
ab -n 100 -c 10 http://a.com/
-c 一次产生的请求个数。默认是一次一个。
-n #发起多少次请求,在测试会话中所执行的请求个数。默认时,仅执行一个请求。
#详解
限制请求 二进制地址 限制策略的名称 占用10M空间 允许每秒1次请求
limit_req_zone $binary_remote_addr zone=req_zone:10m rate=1r/s;
应用 限制策略名称
limit_req zone=req_zone;
#案列
vim /etc/nginx/nginx.conf
http {
limit_req_zone $binary_remote_addr zone=req_zone:10m rate=1r/s;
}
vim
location / {
limit_req zone=req_zone; #使用
root /usr/share/nginx/html;
index index.html index.htm;
}
#限制连接次数
ngx_http_limit_conn_module