Create AWS Application Load Balancer Rule which trim off request's prefix without using additional reverse proxy like nginx, httpd
Asked Answered
O

2

15

Basically, I have a couple of services. I want to forward every requests with prefix "/secured" to server1 port 80 and all other requests to server 2 port 80. The problem is that on server1, I am running service which accept the request without "/secured" prefix. In other words, I want to forward every requests such as "http://example.com/secured/api/getUser" to server1 as "http://example.com/api/getUser" (remove /secured from request' path).

With AWS ALB, currently the request is sent as http://example.com/secured/api/getUser; which forces me to update my server1's code so that the code handles requests with /secured prefix which doesn't look good.

Is there any easy way to solve this with ALB?

Thanks.

Ochs answered 4/9, 2016 at 13:59 Comment(1)
The ALB isn't sophisticated enough to do this. You will have to use a reverse proxy for this.Safford
I
6

I can confirm that this is unfortunately not possible with the ALB alone - and I agree it really should be.

AWS states:

Note that the path pattern is used to route requests but does not alter them. For example, if a rule has a path pattern of /img/*, the rule would forward a request for /img/picture.jpg to the specified target group as a request for /img/picture.jpg.

Infliction answered 29/9, 2017 at 3:24 Comment(3)
Things have moved on, this is a 5 year old question - you can do this through Route53 now - if you're a programmer you will need DevOps support thoughInfliction
Mr @kong, how can we achieve this using route53 ?Twotone
For anyone who stumbles upon this, I believe this is probably what @kong was referring to #53157927Ramonaramonda
N
5

I had the same issue, and as Mark pointed out, you can use reverse proxy on your server and do something like this (this is Nginx configuration):

server {
  listen 80 default_server;

  location /secured/ {
    proxy_pass http://localhost:{service_port}/;
  }
}

This will strip the /secured part and proxy everything else to your service. Just be sure to have the trailing / after the service port.

Naphthyl answered 22/11, 2016 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.