I want to use Application Load Balancer listener rules to redirect HTTP requests to HTTPS.
Resolution
Note: The following resolution applies only to Application Load Balancer. If you're using Classic Load Balancer, then see How do I redirect HTTP traffic to HTTPS on my ELB Classic Load Balancer?
Confirm your load balancer's type
Complete the following steps:
- Open the Amazon Elastic Compute Cloud (Amazon EC2) console.
- In the navigation pane, under Load Balancing, choose Load Balancers.
- Find the load balancer that you're creating a listener rule for. In the Type column, note whether the load balancer is listed as application, classic, network, or gateway.
Note: Before you complete the following steps, you must first create a target group.
Create an HTTP listener rule that redirects HTTP requests to HTTPS
To create an HTTP listener rule and redirect requests to HTTPS, complete the following steps:
Note: If you already have an HTTP listener, the proceed to the next set of steps.
- Open the Amazon EC2 console.
- In the navigation pane, under Load Balancing, choose Load Balancers.
- Select your load balancer, and then choose Listeners, Add listener.
- For Protocol: port, choose HTTP. You can either keep the default port, or specify a custom port.
- For Default actions, choose Add action, redirect to, and then enter port 443. If you don't use the default port, then choose a different port. For more details, see Rule action types.
- Complete the steps in the Create an HTTPS listener section.
If you already have an HTTP listener, then complete the following steps to redirect HTTP requests to HTTPS:
- Select your load balancer, and then choose HTTP Listener.
- Under Rules, choose View/edit rules.
- Choose Edit Rule to modify the default rule to redirect all HTTP requests to HTTPS. Or, you can insert a rule between the existing rules.
- Under Then, delete the existing condition, and then add the new condition with the Redirect to action.
- For HTTPS, enter 443 port.
- Keep the default for the remaining options.
Note: To change the URL or return code, modify the remaining options.
- To save, choose the checkmark icon.
Create an HTTPS listener
Note: If you already have an HTTPS listener with a rule to forward requests to the target group, then proceed to Verify that the security group of the Application Load Balancer allows traffic on 443.
Complete the following steps:
- Choose Listeners, Add listener.
- For Protocol: port, choose HTTPS. Keep the default port, or specify a custom port.
- For Default actions, choose Add action, Forward to.
- Select a target group that hosts application instances.
- Select a predefined security policy for your configuration.
- Choose Default Security Certificate. If you don't have one, then request a security certificate.
- Choose Save.
Verify that the security group of the Application Load Balancer allows traffic on 443
Complete the following steps:
- Choose the load balancer's description.
- Under Security, choose Security group ID.
- Verify the inbound rules. The security group must have an inbound rule that allows traffic on HTTP and HTTPS.
If there are no inbound rules, then complete the following steps to add them:
- Choose Actions, Edit Inbound Rules.
- Choose Add rule.
- For Type, choose HTTPS.
- For Source, choose Custom (0.0.0.0/0 or Source CIDR).
- Choose Save.