基于AWS Application Load Balancer(ALB)路径的路由未按预期运行 [英] AWS Application Load Balancer (ALB) path based routing not functioning as expected

查看:242
本文介绍了基于AWS Application Load Balancer(ALB)路径的路由未按预期运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究POC,以证明使用Express通过Application Load Balancer到一组非常基本的 hello world node.js应用程序的基于AWS路径的路由。没有适当的基于路径的路由,并且没有多个侦听器,每个应用程序只有1个侦听器,每个侦听器和应用程序都按预期工作。因此,目标组中的目标均已通过健康检查,并显示为健康。但是,当我在其中一个侦听器上切换到基于路径的路由实现(删除另一个不必要的侦听器)时,两个应用程序都收到以下错误:

I am working on a POC to prove out AWS path based routing through an Application Load Balancer to a set of very basic "hello world" node.js applications using express. Without the path based routing in place and having multiple listeners, 1 listener for each application, each respective listener and application is working as expected. Therefore, the targets within the Target Groups have both passed health checks and are shown as healthy. However, when I switch to the path based routing implementation on 1 of the listeners (deleting the other unnecessary listener) I get the following error for both applications:


无法获取/ expressapp

无法获取/ expressapp2

Cannot GET /expressapp
Cannot GET /expressapp2

我已经仔细阅读了以下文档以试图找出问题所在:
http:// docs .aws.amazon.com / elasticloadbalancing / latest / application / load-balancer-listeners.html#path-conditions

I have gone through the following documentation to try to figure out the issue: http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-listeners.html#path-conditions

我缺少什么?有任何疑难解答的想法吗?

What am I missing? Any troubleshooting ideas?

推荐答案

我相信您会遇到此错误,因为相关服务不希望接收以开头的路径 / expressapp / expressapp2 。当ALB将流量转发到您的服务时,路径将保持不变。

I believe that you are getting this error because the services in question do not expect to receive paths prefixed with /expressapp and /expressapp2. When the ALB forwards traffic to your service, the path remains intact.

ALB无法处理前缀的剥离。如果您无权访问应用程序的源代码,则在将其发送到应用程序之前,需要使用某种反向代理(如nginx)重写网址。

Stripping off the prefix cannot be handled by ALB. If you don't have access to the source code of the apps, you will need to use some kind of reverse-proxy like nginx to rewrite the urls before sending them onto the app.

如果您可以访问源代码,则express支持更改基本URL,而无需修改代码。您可以将url前缀的值作为环境变量读取,并相应地配置各自的服务环境。

If you have access to the source code, express supports changing the base url without modifying the code. You can read a value for the url prefix in as an environment variable and configure your respective service environments accordingly.

这篇关于基于AWS Application Load Balancer(ALB)路径的路由未按预期运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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