Reputation: 191
Let me explain our architecture first.
www.example.com CNAME points to cloudfront distribution (d3xxxxx.cloudfront.net)
Origin for the cloudfront: route.example.com. We had select **Whitelist Headers ** as HOST in cloudfront distribution
SSL installed on Cloudfront for the domain : www.example.com
route.domain.com points to Google cloud server which has apache webserver and wordpress installed.
Issue 1. When we hit the URL www.example.com without applying SSL certificate, the home page loads www.example.com however internal links redirecting to 'route.example.com' instead of www.example.com. We believe its because of siteurl on wordpress uses route.example.com
Issue 2. After applying SSL certificate on cloudfront, when we hit the URL 'https://www.example.com', the website ended up too many redirects
We have tried the URL "WordPress + CloudFront Flexible SSL ends up in redirect loop (https)" and it doesn't seems to be helping us.
Goal: We want www.example.com to use cloudfront distribution along with SSL and doesnt want to expose webserver to enduser. The origin of the cloudfront should be route.example.com which will have wordpress application.
Any help would be appreciated.
Upvotes: 12
Views: 8343
Reputation: 5915
vlence's answer is good only if internal traffic between CloudFront and WordPress is NOT secured by SSL. In my case, traffic is secured, but the problem remains.
My solution:
index.php
Root cause for the issue is that CF do not properly pass request if there is no any path. In this case, main website. The root cause of the problem is that CF does not forward the request correctly if there is no path.
Upvotes: 0
Reputation: 4908
I know this is an old question, but, as I ended up here I thought I'd post my mistake! We are using Lightsail.
At the bottom of the details
page of your distribution you can set how it pulls content from your source. We had it set to http
when our site in fact is https
(as I expect most people's is).
Changing this fixed the redirect issue.
Upvotes: 0
Reputation: 11
Cloudfront Distribution SettingsI know this is old but I found one cause of this to be if you set the default root object on your distribution to "index.php" for a wordpress site, it will cause these infinite redirects.
Leave this optional parameter blank if your caching a wordpress site!
Upvotes: 1
Reputation: 495
We had a similar problem. In our case though we weren't using a custom domain name but the CloudFront URL.
To get HTTPS to work correctly we had to do two things:
Make sure the CloudFront-Forwarded-Proto
header is forwarded in all cache behaviors, including the default cache behavior.
Add the following code snippet to wp-config.php
before require_once( ABSPATH . 'wp-settings.php' );
:
if (isset($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'])
&& $_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
The code snippet essentially tells WordPress that we're running behind a reverse proxy. This gets it to respond to HTTPS requests correctly.
Upvotes: 36