如何根据请求正文使用HAProxy路由流量(反向代理) [英] How to route traffic (reverse Proxy) with HAProxy based on request body

查看:325
本文介绍了如何根据请求正文使用HAProxy路由流量(反向代理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据以下POST正文中标识的URL将以下请求路由至适当的服务器。我希望通过使用HAProxy的反向代理来完成此操作。

I am attempting to route the following request to the appropriate servers based on the URL identified in the POST body below. I am hoping to accomplish this via a reverse proxy using HAProxy.

例如我想将所有请求定向到HAProxy,然后让HAProxy检查POST正文中是否存在某些值(例如,通知url值 pingpong),如果是这种情况,请将流量路由到我将在其中指定的endopint

E.g. I would like to direct all requests to HAProxy, than have HAProxy check if certain values exist in the POST body (E.g. the notification url value "pingpong"), and if this is the case, route the traffic to an endopint I will specify in the configs.

POST /someURL/file.jsp HTTP/1.1
Host: 10.43.90.190:80
Content-Type: application/json
Connection: keep-alive
Accept: */*
Content-Length: 256

{"Info": {"groupName":"thisgroup1","Id":"M1234R456","id2":"TUP1234",
    "countryCode":"USA","carrierCode":"USAIC","e164Address":"123456768789",
    "notificationURL":"http:\/\/www.pingpong.com\/notify",
    "timestamp":"2014-03-04T17:33:30.000Z"}}

是否可以使用acl搜索内容 pingpong请求正文,并基于此值,我是否可以对其进行适当路由?

Is there any way to use an acl to search for the content, "pingpong" in the request body, and based on this value, I would route it appropriately?

谢谢!

推荐答案

这可以使用简单的方法完成访问控制列表(ACL)。但是,直到Haproxy 1.6(2015年10月)之前,这才成为可能,在那里您可以在前端中包含此选项:

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:

选项http-缓冲请求

此选项使Haproxy可以进入身体。然后,您可以使用req.body访问正文。示例:

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.

有关访问正文内容的更多信息,请参见此处,有关ACL的信息可以此处

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

这篇关于如何根据请求正文使用HAProxy路由流量(反向代理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆