Search code examples
haproxy

combine stick-table with url pattern


Is it possible to setup a http-request deny rule as a combination of http_req_rate and some non static URL pattern?

frontend myfrontend
  stick-table type binary len 20  size 100k  expire 10s  store http_req_rate(10s)
  http-request track-sc0 src

  http-request set-var(txn.url_prefix) path,field(2,/)

  http-request deny if { sc_http_req_rate(0) gt 1000 }

I'd like to count requests for URL prefixes (like var(txn.url_prefix) above) and combine aforementioned http-request deny with this counter.


Solution

  • After reading thoroughly Bot Protection with HAProxy I could elaborate a solution by myself.

    frontend myfrontend
      stick-table type binary size 1m expire 5m store gpc0,gpc0_rate(30s)
      http-request track-sc0 path,field(2,/)
      http-request sc-inc-gpc0(0)
    
      # optionally configure variables for logging purpose
      # http-request set-var(req.path_field2) path,field(2,/)
      # http-request capture var(req.path_field2) len 100
      # http-request set-var(req.gpc0_rate) sc_gpc0_rate(0)
      # http-request capture var(req.gpc0_rate) len 10