How to route traffic (reverse Proxy) with HAProxy based on request body

杀马特。学长 韩版系。学妹 提交于 2019-12-05 16:12:44

This can be done using a simple Access Control List (ACL). However, This wasn't possible up until Haproxy 1.6 (October 2015), where you can include this option in your frontend:

option http-buffer-request

This option gives Haproxy access to the body. Then you can use req.body to access the body. Example:

frontend http-in
             bind *:80
             option http-buffer-request
             acl redirect_pingpong req.body -m reg [insert your regular expression here]
             use_backend pingpong_backend if redirect_pingpong

             default_backend web_bk

And then go on to define your backends.

Further information on accessing body content can be found here and information about ACLs can be found here.

there is possibility to work it out in nginx / tengine but i still not found that in HAProxy, still if it is possible for you to switch to tengine/nginx, you can use nginx_http_lua_module. Still i must warn you, it have some performance issues that i have not solved yet,

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!