gpt4 book ai didi

node.js - 配置负载均衡器路由到实例的不同页面?

转载 作者:太空宇宙 更新时间:2023-11-03 23:18:00 28 4
gpt4 key购买 nike

  • 我在实例 x 前面有一个 AWS 负载均衡器。
  • 实例 x 运行于端口 3000。实例 x 有两个页面,即 x/abc 和 x/zyx。
  • 当前 x 的负载均衡器有两个监听器,即 80 -> 30008080 -> 3000。然后 ping /

Requirement: I has two servers that want to communicate to instance x. Server 1 wants to send http request to x/abc and server 2 wants to send http request to x/zyx.

如何配置 LB 以路由到特定页面,例如x/abc 和 x/zyx? 或者以不同的方式写我的请求?

代码1:服务器1想要向x/abc发出http请求

// url is the DNS of load balancer... this should go to x/abc(?)
request({
url: "LoadBalancer-11122232.us-west-2.elb.amazonaws.com:80",
method: "POST",
json: true,
body: tweetJSON
}

代码2:服务器2想要向x/zyx发出http请求

// url is the DNS of load balancer... this should go to x/abc 
// DO I EVEN NEED TWO DIFFERENT PORT LISTENERS(?)
request({
url: "LoadBalancer-11122232.us-west-2.elb.amazonaws.com:8080",
method: "POST",
json: true,
body: tweetJSON
}

最佳答案

您无需将负载均衡器配置为将请求路由到不同的端点,这更多是反向代理的工作,例如 Nginx .

负载均衡器提供单个端点进行调用,并将来自客户端的请求转发到许多相同服务器之一。其目标是在许多服务器之间共享高负载。

在您的情况下,您仍然可以混合使用负载均衡器,但就路由而言,我建议您完整地寻址 URL:

代码1:服务器1想要向x/abc发出http请求

// url is the DNS of load balancer plus the route (/abc)
request({
url: "https://LoadBalancer-11122232.us-west-2.elb.amazonaws.com/abc",
method: "POST",
json: true,
body: tweetJSON
}

代码2:服务器2想要向x/zyx发出http请求

// url is the DNS of load balancer plus the route (/zyx)
request({
url: "https://LoadBalancer-11122232.us-west-2.elb.amazonaws.com/zyx",
method: "POST",
json: true,
body: tweetJSON
}

如果您需要阻止客户端访问后端 URL,则需要某种形式的身份验证来识别服务器 2。

关于node.js - 配置负载均衡器路由到实例的不同页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52981024/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com