Home > Back-end >  AWS ALB Create Path-Based Routing - Redirect subdirectory to root
AWS ALB Create Path-Based Routing - Redirect subdirectory to root

Time:01-16

I have one application running on AWS, it runs under the application / directory. I want to create a path-based routing on AWS Load Balancers and run it as two applications, but I get a 404 error. How can I do this with AWS Application Load Balancer without doing anything on the backend?

Structure:

  1. domain.com/server1 (AWS Load Balancer) ---> TargetGroup1 --- > /
  2. domain.com/server2 (AWS Load Balancer) ---> TargetGroup2 --- > /

In short, when I want to access https://lbaddress/test1 address, I want the software running on my backend (working on root folder / ) server to run

Nginx side, i can do as follows.

location ^~ /server1 {
      rewrite ^/server1(.*)$ $1 last; 
}

This rule is not working, faced 404 code.

CodePudding user response:

Go to your ALB Listeners. In the appropriate listener click on "view/edit rules". There you can add your rules. You want to do a path-based routing, so you will add this rule:

IF PATH is /server1/* THEN Forward to TG1
IF PATH is /server2/* THEN Forward to TG2

/* is added so it matches anything in the path start starts with the appropriate server.

CodePudding user response:

AWS ALB does not support path rewriting. When request domain.name/server1/foo is forwarded, the target host will see /server1/foo, not /foo. Since you likely don't have /server1 configured on your target host, it will return 404.

  •  Tags:  
  • Related