1

I am planning to host 3 URLs on one Ec2 instance(linux and not container based) and do path based routing. Can you please help to find out whether ALB supports multiple URLs within the same instance. Note: I understand its possible to route to containers within a single instance but my requirement is not containers

Dave
  • 181
  • 8

1 Answers1

1

Containers aren't actually visible to ALB -- even if you are using them, what matters is the TCP port the HTTP server is listening on. If your services each listen on a specific port (which they would necessarily need to do, otherwise they wouldn't be different services), then yes, ALB can route requests to multiple services on the same instance, based on the path.

Each service would be associated with a unique target group on the ALB, registered using the port where it listens for requests from the balancer.

Michael - sqlbot
  • 22,658
  • 2
  • 63
  • 86
  • I have all 3 URLs listening on port 443 as they are all webpages. I think in my case ALB can not route to 3 URL on the same instance as the port is same for 3 URLs. Correct ? – Dave Mar 26 '18 at 07:17
  • @Dave you can't have them all listening on port 443 **and** simultaneously need a balancer to actively choose which one to route to... because they're already all on 443. There's only one target. You just point the balancer to 443. The balancer forwards everything unless you give it a reason not to. – Michael - sqlbot Mar 26 '18 at 18:46
  • can I use apache virtual host to create 3 URLs domains and put the respective web pages on diff directory. Then configure ALB to forward traffic on port 443 and rest Apache will be do traffic routing. – Dave Mar 27 '18 at 19:10
  • Yes, exactly. The ALB sends all requests to the target by default. Apache should do the rest. Note that you may want to use port 80, on apache, instead of 443. ALB will handle all the SSL for you and set the `X-Forwarded-Proto: https` header to indicate that the external portion of the request was handled with TLS (SSL). – Michael - sqlbot Mar 27 '18 at 19:19
  • Thanks @Michael. Take Away is : If we have single server then Apache has to take care of routing. And if we have 3 servers then ALB path based routing can work if we configure 3 target groups. Correct? – Dave Mar 27 '18 at 19:37
  • Close, but not quite. You could have one instance of apache serving three different applications on ports 8082, 8084, 8086... or multiple instances of apache... or you could have nginx on 1111 and Express.js on 2222 and Mojolicious on port 3333... or any combination. What matters is how many distinct targets there are -- they can be on 1 instance, or 1 each on 3 instances, or all 3 apps running on each of 6 instances, etc. This is what's cool about ALB that ELB Classic coudn't do -- select a distinct *target group* (one or more ports, on one or more instances) *if you need for it to do so*. – Michael - sqlbot Mar 27 '18 at 20:07