首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HAProxy减缓来自特定IP的连接

HAProxy减缓来自特定IP的连接
EN

Stack Overflow用户
提问于 2017-05-04 07:42:06
回答 1查看 2.7K关注 0票数 2

是否有人知道如何使用HAProxy将传入的请求添加到到达的最大请求数量后再延迟,而不仅仅是拒绝或发送状态代码,实际上是对特定IP地址的请求进行排队,如果不是太多,则在数量减少后允许。

使用文档所有上述部分似乎都是可能的,尽管合并似乎是一个问题。

我的前端有以下内容:

代码语言:javascript
复制
#Add counter to ip in ratelimiting table
tcp-request content track-sc0 src table ratelimiting

# if alot of requests (more than 1000) - reject
acl mark_alot_of_requests sc0_conn_rate(ratelimiting) gt 1000
tcp-request content reject if mark_alot_of_requests TRUE

#If concurrent requests >= 100 from a single IP return 429
acl mark_too_many_requests sc0_conn_cur(ratelimiting) ge 100
use_backend 429_slow_down if mark_too_many_requests

然后

代码语言:javascript
复制
backend 429_slow_down
    mode http
    timeout tarpit 5s
    reqitarpit .
    errorfile 500 /etc/haproxy/errors/429.http
    http-request tarpit

是我的讲坛,虽然我确实拖慢了他们,但并没有像我最初想的那样行事。

在“侦听”中创建了分级表,如下所示:

代码语言:javascript
复制
listen ratelimiting
    mode http
    stick-table type ip size 1m expire 1h store conn_rate(5000),conn_cur

非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-06 14:45:49

我会在前端部分使用inspect-timeout和'WAIT_END`‘

代码语言:javascript
复制
frontend mywww

   tcp-request content track-sc0 src table ratelimiting

   acl mark_alot_of_requests sc0_conn_rate(ratelimiting) gt 1000
   tcp-request content reject if mark_alot_of_requests TRUE

   acl mark_too_many_requests sc0_conn_cur(ratelimiting) ge 100

   # delay for request inspect, it will be used for effectively client delay 
   tcp-request inspect-delay 1000ms

   # if client is not too fast let it through
   tcp-request content accept unless mark_too_many_requests

   # too fast clients, will need to wait entire inspect-delay
   tcp-request content accept if WAIT_END

   use_backend some_normal_backend
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43776786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档