Lightsail WordPress + AWS for WordPress plugin + CloudFront causing CSSto not load properly (ERR_TOO_MANY_REDIRECTS)

Type: Bitnami Support Tool

Description:
Hi

I’m trying to set up CloudFront along with a Lightsail WordPress instance, however in doing so it seem to be causing too many redirects and therefor cannot load the CSS and images. See image for reference: https://i.stack.imgur.com/mDlBl.png

I’m trying to sum up my config here:

  • Route 53 A record for the naked domain (domain.xxx) pointing to Lightsail server public IP
  • Route 53 CNAME record for www.domain.xxx pointing to the CloudFront distribution
  • CloudFront distribution has been created with the AWS for WordPress plugin, however added CloudFront-Fordwarded-Proto header to each of the behaviors created as suggested elsewhere
  • SSL certificate created with the AWS for WordPress plugin for the www.domain.xxx, no additional name.
  • Another SSL certificate (with ACM) is issued to *.domain.xxx with the additional name domain.xxx this is used for various subdomains.
  • Along with this another SSL certificate has been generated on the Lightsail instance using Let’s Encrypt (for when not using CloudFront) - however I have not tested with deleting this, I do remember it asking whether to redirect non-www to www and the other way around.
  • htaccess.conf file additions:
# BEGIN rlrssslReallySimpleSSL rsssl_version[5.0.10]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
  • .htaccess file contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
  • wp-config.php file additions:
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/'); 
if(isset($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO']) &&
$_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on'; }

I have tried various solutions until now, also trying to force HTTPS through the distribution, but the same issue keeps happening. I’m hoping maybe you can point me in the right direction.

I have created a Bitnami Support Tool dump.

Thanks a lot in advance.

Sorry for the bad markdown, when creating the ticket there was no editor or live preview. and I cannot edit it afterwards it seems.

  • htaccess.conf file additions:
    # BEGIN rlrssslReallySimpleSSL rsssl_version[5.0.10]
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTPS} !=on [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    </IfModule>
    # END rlrssslReallySimpleSSL
  • .htaccess file contents:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
  • wp-config.php file additions:
    define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
    define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/'); 
    if(isset($_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO']) &&
    $_SERVER['HTTP_CLOUDFRONT_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on'; }

Hi @sonnymeyer,

We have a Support Tool that will gather relevant information for us to analyze your configuration and logs. Could you please execute it on the machine where the stack is running by following the steps described in the guide below?

How to Run the Bitnami Support Tool in a cloud image or virtual machine

Please note that you need to paste the code ID that is shown at the end.

Regards,
Michiel

Hi,

Thanks for your reply. Can I send a Dropbox link to you privately? It seems I don’t have access to messaging either.

The guide to creating a manual dump told me to create the ticket this way if I wasn’t able to upload it through the support tool. I have created the dump and I’m ready with a link, but it also states not to post it publicly because of the sensitive information available.

Thanks,
Sonny

Hi @sonnymeyer,

I’ve sent you my email address through a private message. Could you please share the link with me and notify me in this public thread?

Regards,
Michiel

I’ve sent it now, thanks a lot!
Sonny

Hi @sonnymeyer,

Did you configure a load balancer? In that case did you follow the steps in this guide?

https://docs.bitnami.com/aws/how-to/configure-elb-ssl-aws

Regards,
Michiel

Hi @michiel,

Thanks for the reply.

For now, no load balancer configured.

Best,
Sonny

Hi @sonnymeyer

I am taking a look at your issue as well. I have sent you a private message requesting access to the bnsupport file. Please, update the thread notifying me once you have shared it to me :slightly_smiling_face:

Thanks in advance!

Thanks a lot @jcarmona,

I have replied to your message. Let me know if I can do anything else to help.

Sonny

Hi again @sonnymeyer!

Thanks for replying to the message and sending the support bundle. I have tried to access your website but I could not experience any ERR_TOO_MANY_REDIRECTS with the resources (maybe you have rolled back the changes you mentioned by now).

I noticed that you are using AWS for WordPress plugin to set up CloudFront in your site. Unfortunately, we don’t have any guide on that plugin, but there is official documentation on how to set it up:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/WordPressPlugIn.html#WordPressPlugin-install

Have you followed that guide?


Nevertheless, we have a guide on how to set up CloudFront using another plugin named W3 Total Cache. This guide covers all the process, from creating the bucket to configuring WordPress. I think you you might find it helpful:

https://docs.bitnami.com/aws-templates/apps/wordpress-production-ready/administration/configure-cdn/#configure-wordpress-to-use-aws-cloudfront

Best regards,
Jose Antonio Carmona


Was my answer helpful? Click on :heart:

Hi @jcarmona

Yeah I had to rollback as the site is live, I haven’t set up a test env yet.

I haven’t followed the guide however I followed the instructions in the plugin - I will take a closer look at the guide.

I was considering trying W3 Total Cache, as a friend of mine seemed to have the same issue a while back, and he mentioned he got it working with tweaking some settings in W3 Total Cache, so that might be worth a try instead.

Thanks!

1 Like