How can I set up host-based routing using an Application Load Balancer?
To Nha Notes | Sept. 23, 2022, 11:53 a.m.
I have multiple domains that are served by the same Application Load Balancer. I'm using different target groups for each domain. I need to forward the traffic for each domain to their respective target groups. How can I set up host-based routing using an Application Load Balancer?
Resolution
- Open the Amazon Elastic Compute Cloud (Amazon EC2) console.
- On the navigation pane, choose Load Balancers under Load Balancing.
- Select your load balancer, and then choose Listeners.
- Choose View/edit rules for the load balancer listener that you want to use.
- Choose the Add rule icon (the plus sign).
- Choose Insert Rule.
- Choose Add condition.
- Choose Host header.
- Enter the hostname for your domain (for example, example1.com).
Choose the checkmark icon to save the condition.
- Choose Add action to add the desired actions for your condition. To save the actions, choose the checkmark icon.
- Choose Save.
- Repeat steps 5-12 to add additional rules to route different domains to different target groups.
Notes:
- In Route53, add multiple CNAME records for each domain which point to same ALB DNS name.
- sub1.domain.com -> xxx.ap-northeast-1.elb.amazonaws.com
- sub2.domain.com -> xxx.ap-northeast-1.elb.amazonaws.com
- To use the same set of target groups to serve multiple domains, add multiple hostnames for your domains.
- Rules are prioritized based on their position in the rule list. If necessary, you can reorder rules to modify the rule priorities.
- If a request's host header doesn't match the host headers in any of the rules, the actions configured in the listener's default rule are performed.
References
https://aws.amazon.com/premiumsupport/knowledge-center/elb-configure-host-based-routing-alb/