Aws routing to different ELB Aws routing to different ELB nginx nginx

Aws routing to different ELB


ELB does not support routing of HTTP requests to different back-ends based on the path (or any other request parameters). All of the back-ends for a given ELB are expected to be able to serve all requests.

The only way to do this "serverless" with AWS componentry -- without using something like Nginx or HAProxy behind ELB -- and without redirecting to different subdomains -- is to create an ELB for each independent collection of app servers, and then use CloudFront for the entire site. CloudFront allows you to declare multiple origin servers (one for each ELB) and then use cache behavior path patterns to determine which paths are routed to which origin (in this case, which ELB).

Note that this is a perfectly valid use case for CloudFront even if you don't need the caching (it can be selectively disabled).

As a bonus, this also makes it simple to integrate static content stored in S3 into your site, since you can also declare one or more S3 buckets as Origin servers, and CloudFront will send the requests directly to S3 for the matching paths.


The common way to do this is to have two ELBs and to use a subdomain name to route traffic to its specific ELB:

www.website.com/login -> login.website.comwww.website.com/backoffice -> backoffice.website.com 

the instance can redirect to a specific folder on the site if needed. Likewise the existing website can have redirection to the subdomain specific URIs.