How to Set Up a Secure Website Using AWS LightSail & Load Balancer
Step 1: Create and Configure AWS LightSail Instances
- Create Two LightSail Instances
- Log in to your AWS account.
- Navigate to LightSail.
- Create two instances in your desired region.
- Enable VPC Peering
- Go to Account settings and enable VPC peering.
- Choose Advanced settings if needed for your setup.
Step 2: Set Up Target Groups and Register Instances
- Create Two Target Groups
- Go to the EC2 Dashboard and select Target Groups under the Load Balancing section.
- Create the first target group using IP addresses and add the private IP of the first Lightsail instance.
- Create the second target group in the same manner, adding the private IP of the second Lightsail instance.
Step 3: Request an SSL Certificate via AWS Certificate Manager (ACM)
- Request a Certificate
- Navigate to AWS Certificate Manager (ACM).
- Request a public certificate and add the Fully Qualified Domain Name (FQDN) for your root domain (e.g., cloud24.mycloud.academy).
- Add a wildcard domain (e.g., *delhi.cloud24.mycloud.academy) in the additional domain names section.
- Verify Domain Ownership
- Add the provided CNAME records to your Route 53 hosted zone for domain verification.
Step 4: Create and Configure a Load Balancer
- Create a Load Balancer
- Go to EC2 Dashboard and select Load Balancers.
- Create an Application Load Balancer (ALB) and configure it to route traffic.
- Add HTTPS Listener
- Select HTTPS as the listener protocol.
- Attach the target group where the first instance's private IP is registered.
- Select the SSL certificate from ACM.
- Redirect HTTP to HTTPS
- Go to the HTTP Listener settings and edit the rule.
- In Routing actions, select Redirect to URL.
- Set the redirect URL to https://#{host}:443/#{path}?#{query} to ensure all HTTP requests are redirected to HTTPS.
- Configure HTTPS Listener for Subdomain
- Edit the HTTPS listener rule.
- Add a condition for Host Header with the subdomain name.
- Set the action to forward traffic to the second target group.
Step 5: Configure DNS with Route 53
- Add CNAME Records in Route 53
- Copy the DNS name of your ALB.
- Create a CNAME record in Route 53 for your root domain (e.g., cloud24.mycloud.academy).
- Create a CNAME record for your subdomain using the same ALB DNS name.