Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Api 单侧前交叉韧带。默认情况下,阻止与Haproxy的所有连接,并仅允许特定IP_Api_Haproxy_Sticky_Rate Limiting - Fatal编程技术网

Api 单侧前交叉韧带。默认情况下,阻止与Haproxy的所有连接,并仅允许特定IP

Api 单侧前交叉韧带。默认情况下,阻止与Haproxy的所有连接,并仅允许特定IP,api,haproxy,sticky,rate-limiting,Api,Haproxy,Sticky,Rate Limiting,我正在尝试使用haproxy解决一个场景。场景如下所示 默认情况下阻止所有IP 仅允许从特定IP地址进行连接 如果任何连接来自whilelist IP,如果在30秒内超过10个并发连接,则If应拒绝 我想这样做是为了减少对服务器的API调用数量。谁能帮我一下吗 谢谢前两件事很简单,只允许白名单上的IP acl whitelist src 10.12.12.23 use_backend SOMESERVER if whitelist 第三个-节流-需要使用(有许多数据类型-计数器conn、s

我正在尝试使用haproxy解决一个场景。场景如下所示

  • 默认情况下阻止所有IP
  • 仅允许从特定IP地址进行连接
  • 如果任何连接来自whilelist IP,如果在30秒内超过10个并发连接,则If应拒绝
我想这样做是为了减少对服务器的API调用数量。谁能帮我一下吗


谢谢

前两件事很简单,只允许白名单上的IP

acl whitelist src 10.12.12.23
use_backend SOMESERVER if whitelist
第三个-节流-需要使用(有许多数据类型-计数器conn、sess、http、rates…)作为速率计数器:

#                    max entries              count request in 60s periods
stick-table type ip   size 200k   expire 100s store http_req_rate(60s) 
下一步你必须填写表格,例如IP

tcp-request content track-sc0 src 
# more info at http://cbonte.github.io/haproxy-dconv/1.5/configuration.html#4.2-tcp-request%20connection
最后是acl:

# is there more than 5req/1min from IP
acl http_rate_abuse sc0_http_req_rate gt 5

# update use_backend condition
use_backend SOMESERVER if whitelisted !http_rate_abuse
例如,某些自定义错误的工作配置文件:

global
    log /dev/log    local1 debug

defaults
    log     global
    mode    http
    option  httplog
    retries 3
    option redispatch
    maxconn 2000
    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

frontend http
    bind *:8181

    stick-table type ip   size 200k   expire 100s store http_req_rate(60s)
    tcp-request content track-sc0 src

    acl whitelist src 127.0.0.1
    acl http_rate_abuse sc0_http_req_rate gt 5 
    use_backend error401 if !whitelist
    use_backend error429 if http_rate_abuse
    use_backend realone

backend realone
    server local stackoverflow.com:80

# too many requests
backend error429
    mode http
    errorfile 503 /etc/haproxy/errors/429.http

# unauthenticated
backend error401
    mode http
    errorfile 503 /etc/haproxy/errors/401.http
注意:错误处理有点棘手。由于上述错误后端缺少服务器条目,haproxy将抛出HTTP 503,
errorfile
捕获它们并发送不同的错误(使用不同的代码)

示例
/etc/haproxy/errors/401.http
内容:

HTTP/1.0 401 Unauthenticated
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>401 Unauthenticated</h1>
</body></html>
HTTP/1.0 429 Too many requests
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>429 Too many requests</h1>
</body></html>

前两件事很简单,只允许白名单上的IP

acl whitelist src 10.12.12.23
use_backend SOMESERVER if whitelist
第三个-节流-需要使用(有许多数据类型-计数器conn、sess、http、rates…)作为速率计数器:

#                    max entries              count request in 60s periods
stick-table type ip   size 200k   expire 100s store http_req_rate(60s) 
下一步你必须填写表格,例如IP

tcp-request content track-sc0 src 
# more info at http://cbonte.github.io/haproxy-dconv/1.5/configuration.html#4.2-tcp-request%20connection
最后是acl:

# is there more than 5req/1min from IP
acl http_rate_abuse sc0_http_req_rate gt 5

# update use_backend condition
use_backend SOMESERVER if whitelisted !http_rate_abuse
例如,某些自定义错误的工作配置文件:

global
    log /dev/log    local1 debug

defaults
    log     global
    mode    http
    option  httplog
    retries 3
    option redispatch
    maxconn 2000
    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

frontend http
    bind *:8181

    stick-table type ip   size 200k   expire 100s store http_req_rate(60s)
    tcp-request content track-sc0 src

    acl whitelist src 127.0.0.1
    acl http_rate_abuse sc0_http_req_rate gt 5 
    use_backend error401 if !whitelist
    use_backend error429 if http_rate_abuse
    use_backend realone

backend realone
    server local stackoverflow.com:80

# too many requests
backend error429
    mode http
    errorfile 503 /etc/haproxy/errors/429.http

# unauthenticated
backend error401
    mode http
    errorfile 503 /etc/haproxy/errors/401.http
注意:错误处理有点棘手。由于上述错误后端缺少服务器条目,haproxy将抛出HTTP 503,
errorfile
捕获它们并发送不同的错误(使用不同的代码)

示例
/etc/haproxy/errors/401.http
内容:

HTTP/1.0 401 Unauthenticated
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>401 Unauthenticated</h1>
</body></html>
HTTP/1.0 429 Too many requests
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>429 Too many requests</h1>
</body></html>

你需要尝试一下,告诉我们你在哪里卡住了。HAProxy配置文件可能涉及某种程度的“编程”,但我怀疑你会发现,对于HAProxy问题,你会发现这是一个比堆栈溢出更合适的场所。你需要尝试一下,并告诉我们你在哪里遇到了问题。HAProxy配置文件可能涉及某种程度的“编程”,但我怀疑您会发现,对于HAProxy问题,它比堆栈溢出更合适。