【发布时间】:2019-01-29 14:45:36
【问题描述】:
Nginx 使用漏桶的方式来限制请求率。 Nginx http_limit_req_module.
这意味着如果我将限制设置为 100 个请求/秒,然后我被 120 个请求/秒淹没,100 个请求将正常处理,但 20 个请求将被 503 错误处理。
如何使用 Haproxy 进行设置?
我阅读了很多关于 sc_http_req_rate 的文档,但由于速率始终为 120 req/sec。我总是返回 503 错误。
frontend main
bind *:80
acl foo_limited_req sc_http_req_rate(0) ge 100
http-request track-sc0 path table Abuse # Set the URI as the key of the table
use_backend bk1 if foo_limited_req
default_backend web
backend web
server web1 192.168.0.10
backend Abuse
stick-table type string len 128 size 100K expire 30m store http_req_rate(1s)
backend bk1
server listenerror 127.0.0.1:81
listen errorlistener
bind 127.0.0.1:81
mode http
errorfile 503 /etc/haproxy/errors/200-tuned.http
我想为 web 后端提供 100 个请求/秒的流量。以及 bk1 后端的 20 req/sec 盈余。
【问题讨论】:
-
你在正确的轨道上。也许这个博客有帮助? alex.mamchenkov.net/2017/05/17/…
-
我不想拒绝任何连接。我的目标是用特定代码回复超出限制的内容。
标签: haproxy