nginx中含有limit_req_zone 和limit_req
limit_req_zone $binary_remote_addr zone=one:10m rate=2r/s;
limit_req_log_level notice;
http,sever,location等。
limit_req zone=one burst=1000 nodelay;
1秒内请求2次以上,需要客户端等待服务器响应,后续请求被放置到burst内。
如果超过1000个请求,不延迟,直接返回503错误。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>this is error</title>
</head>
<body>
欢迎浏览我们的网站,你的IP访问过于频繁?有点受不住哦。<br/>
请稍候,正在重新连接中...
</body>
</html>
<script language="JavaScript">
function myrefresh(){
window.location.reload();
}
setTimeout('myrefresh()',5000); //指定5秒刷新一次
</script>
#请求限制,文档参考 Module ngx_http_limit_req_module
#连接数限制,文档参考 Module ngx_http_limit_conn_module
## 这里取得原始用户的IP地址
# 获取客户端的真实IP地址的方法,无论中间是否有CDN,代理等。
map $http_x_forwarded_for $clientRealIp {
"" $remote_addr;
~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr;
}
## 针对原始用户 IP 地址做限制
limit_conn_zone $clientRealIp zone=TotalConnLimitZone:20m ;
limit_conn TotalConnLimitZone 50;
limit_conn_log_level notice;
## 针对原始用户 IP 地址做限制
limit_req_zone $clientRealIp zone=ConnLimitZone:20m rate=10r/s;
#limit_req zone=ConnLimitZone burst=10 nodelay;
limit_req_log_level notice;
## 具体服务器配置
server {
listen 80;
location ~ \.jsp$ {
## 最多 5 个排队,由于每秒处理 10 个请求 + 5个排队,你一秒最多发送 15 个请求过来,再多就直接返回 503 错误给你了
limit_req zone=ConnLimitZone burst=5 nodelay;
其它配置设置.......
}
}