连接频率的限制 -limit_conn_module
请求频率的研制 -limit_req_module
tcp三次握手,一次连接可以建立多次http请求
连接限制的语法
#语法1
Syntax:limit_conn_zone key zone=name:size;
Default:——
Context:http
#语法2
Syntax:limit_conn zone number
Default:——
Context:http,server,location
请求限制的语法
#语法1
Syntax:limit_req_zone key zone=name:size rate=rate
Default:——
Context:http
#语法2
Syntax:limit_req zone=name [burst=number] [nodelay]
Default:——
Context:http,server,location
演示:
vi /etc/nginx/conf.d/default.conf
测试请求限制是否生效
安装 ab工具
yum -y install httpd-tools
1.启动配置limit_req zone=req_zone
压测
ab -n 20 -c 20 http://192.168.96.188/1.html
如果生效会打印错误日志如下
2.启动配置limit_req zone=req_zone burst=3 nodelay;
同样测试
ab -n 20 -c 20 http://192.168.96.188/1.html
此时有做延时,请求只有16个
3.配置连接限制limit_conn conn_zone 1方法同上