如何在Nginx UDP LoadBalancer中添加Proxy_pass_header参数到Preserver目标IP

发布于 2025-02-03 23:27:29 字数 769 浏览 4 评论 0原文

我已经在C中创建了一个客户端服务器应用程序。我的客户端位于不同的VM上,服务器位于不同的VM上。 在服务器端,我正在使用nginx加载平衡器,nginx load平衡器接受客户端的请求,然后将请求发送到相应的容器,但是当LoadBalancer将请求发送到容器时,它会修改其标题(即源IP和目标IP),当我获取目标时,来自数据包的IP将容器IP作为目标IP提供,我想要的是我们从数据包中获取实际目标IP的方式。

Client IP : 192.x.x.x
Server IP : 192.x.x.y

Loadbalancer IP : 172.17.x.x
Container IP : 172.17.x.y

Flow :
client -> loadbalacer -> container

Client Sends Header (src : 192.x.x.x, dst 192.x.x.y)
Loadbalancer Recvd Header (src : 192.x.x.x, dst 192.x.x.y)
Loadbalancer Sends Header (src 172.17.x.x, dst 172.17.x.y)
Container Recvd Header (src 172.17.x.x, dst 172.17.x.y)

我实际上在寻找的东西:

Loadbalancer Sends Header (src 192.x.x.x, dst 192.x.x.y)
Container Recvd Header (src 192.x.x.x, dst 192.x.x.y)

I have created a client-server application in C. My client resides on different VM and server resides on different VM.
On server side I am using Nginx load balancer, nginx load balancer accepts request from client and then sends request to respective containers but when loadbalancer send requests to container it modifies its header(i.e source ip and destination ip) and at container when I fetch destination ip from packet is gives container ip as destination ip, what I want is how we get actual destination ip from the packet.

Client IP : 192.x.x.x
Server IP : 192.x.x.y

Loadbalancer IP : 172.17.x.x
Container IP : 172.17.x.y

Flow :
client -> loadbalacer -> container

Client Sends Header (src : 192.x.x.x, dst 192.x.x.y)
Loadbalancer Recvd Header (src : 192.x.x.x, dst 192.x.x.y)
Loadbalancer Sends Header (src 172.17.x.x, dst 172.17.x.y)
Container Recvd Header (src 172.17.x.x, dst 172.17.x.y)

What I am actually looking for :

Loadbalancer Sends Header (src 192.x.x.x, dst 192.x.x.y)
Container Recvd Header (src 192.x.x.x, dst 192.x.x.y)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2025-02-10 23:27:29

如果负载平衡器将请求发送到容器,则最好让src成为加载平衡器的IP。

在您的容器中,要获取启动此请求的客户端的IP地址,请查找标题 x-forwarded-for (在您的情况下,这将是IP 192.xxxx)。

If the load balancer is sending the request to the container, it is best to let the src be the IP of the load balancer.

In your container, to get the IP address of the client who initiated this request, look for the header X-Forwarded-For (in your case, this will be the IP 192.x.x.x).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文