简体   繁体   中英

AWS Application Load Balancer (ALB) path based routing not functioning as expected

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:

Cannot GET /expressapp
Cannot GET /expressapp2

听众规则

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?

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.

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.

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.

I would flip both rules from their respective positions Ie make expressapp2 rule #1 and express app rule #2 for it to work like you want it to.

The ALB evaluates these rules in order of priority and even though the context path is expressapp2 it still matches expressapp and the first rule is evaluated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM