如何根据请求正文使用HAProxy路由流量(反向代理)

编程入门 行业动态 更新时间:2024-10-27 14:18:07
本文介绍了如何根据请求正文使用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\/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路由流量(反向代理)

本文发布于:2023-10-26 01:08:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   流量   正文   HAProxy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!