Nginx限制频繁刷新

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;
        
            其它配置设置.......
    }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值