简体   繁体   中英

Setting up a wordpress website with SSL from AWS certificate Manager behind Load Balancer

I am struggling with an issue for a long time still I don't have a proper solution. The scenario is as follows:

Domain Name: domain-name.com Website Desired URL: https://www.domain-name.com/ Type of Website: Wordpress Web Hosting: AWS DNS Management: Route53 SSL: From AWS Certificate Manager attached with Load Balancer

I tried several ways to do that but didn't work, some of them are as follows:

Case 1: At Route 53 I set bare domain A record with load balancer alias and a CNAME record for www.domain-name.com with value domain-name.com Website URL at wordpress: https://www.domain-name.com Result: This website has too many redirections and the website failed to load

Case 2: At Route 53 I set bare domain and www.domain-name.com both A record with load balancer alias Website URL at wordpress: https://www.domain-name.com At htaccess, I set 301 redirect to https from http Result: I found my website working but it had multiple redirects such as if I request a URL with http://domain-name it took me to http://www.domain-name then again redirected to https://www.domain-name

Case 3: I kept everything same as in case 2 except I changed A record for bare domain to a S3 bucket which had static web hosting enabled and forwarded all the request to www.domain-name but it didn't resolve the multiple redirection issue. I also tried setting up a CloudFront which uses above S3 bucket and updated the A record of the bare domain with the cloudfront alias.

Kindky help me with the correct setting at each level from Route 53 to Load Balancer setting to htaccess to achieve the above in a standard way.

Thanks

You need to take the problem one step at a time. You are trying to do everything at once and thus cannot determine the failing link in the chain.

  1. Make sure you have an A Alias record in Route 53 pointing to your ELB, as described here: http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-elb-load-balancer.html

    On your Route 53 hosted zone, make sure you have a record named www.domain-name.com, Type A, Alias: Yes, Alias Target: name of your ELB

  2. Make sure the listeners on the ELB are correctly configured. After you make everything work on HTTP, you can focus on HTTPS. Due to the fact that traffic within the VPC is considered private and thus secure, your back-end instances should only listen on port 80. So, remove any redirection, start with one listener (80 (HTTP) -> 80 (HTTP)) and after confirming your website is reachable, add the second listener 443 (HTTPS) -> 80 (HTTP).

    Are you using the new ALB or the old, classic ELB?

    Your website should now be served on both http://www.domain-name.com/ and https://www.domain-name.com/ .

  3. You can now implement a redirect on your back-end instances from HTTP to HTTPS, as described here https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

    Also, make sure the correct website address is configured within Wordpress, as it may mess things up.

At route 53 add A record for www and non www domain to Application LB alias. Start with one listener (80 (HTTP) -> 80 (HTTP)) and after confirming your website is reachable, add the second listener 443 (HTTPS) -> 80 (HTTP).

Your website should now be served on both http://www.domain-name.com/ and https://www.domain-name.com/ .

No at htaccess for redirection You have to handle things differently. You won't be checking for https in the normal way because of the SSL Offloading with your Load Balancer. You would need to check the X-Forwarded-Proto

For https://www.domain-name.com it should be as following.

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{SERVER_NAME} ^(www\.)?(.*)$ [NC]
RewriteRule ^.*$ https://www.%2%{REQUEST_URI} [R=301,L]` 

For https://domain-name.com it should be as following.

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{SERVER_NAME} ^(www\.)?(.*)$ [NC]
RewriteRule ^.*$ https://%2%{REQUEST_URI} [R=301,L]` 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM