Reputation: 301
Using aws tools, what's the best way to route traffic to different EC2 instances depending on the URI? For example:
www.website.com/login -> EC2 instance 1 www.website.com/backoffice -> EC2 instance 2
I know I can put an nginx and route all incoming internet traffic through it, but is there a more simple solution?
Upvotes: 4
Views: 125
Reputation: 179414
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.
Upvotes: 4
Reputation: 13648
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.com
www.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.
Upvotes: 0