ERROR: TOO MANY REDIRECTS after setting up load balancer with EC2 t2 micro instance

Keywords: WordPress - AWS - Technical issue - Other
Description:
My website is on EC2 - t2 micro instance

After configuring a Load balancer for my website on EC2, website is not loading and getting the error: TOO MANY REDIRECTS
I followed this documentation; https://docs.bitnami.com/aws/how-to/configure-elb-ssl-aws/#step-4-modify-the-web-server-configuration-on-the-bitnami-application-instance

I did setup the load balancer successfully and modified the Server configuration as advised. (Followed all steps in the documentation)

I found the same issue mentioned in forums several times. The solution they had given was, including this code on wp-config.php file:

if (strpos($_SERVER[‘HTTP_X_FORWARDED_PROTO’], ‘https’) !== false)
$_SERVER[‘HTTPS’]=‘on’;

But I have already added this code and rechecked it several times.

Checked for the system status as well and all services are up and running.
Rebooted the server 2 times

Hope you could support me and provide a solution.

Hello @erandaind93,

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?

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

Regards,
Francisco de Paz

Initiated the support tool and following message came up finally:

The support bundle file was successfully created, but the automatic upload to Bitnami servers failed. You will need to upload it to your Bitnami Support ticket manually. Please locate the following file in your file browser or in your terminal: /tmp/bitnami-wordpress-info-20210406-085645-6372.zip Exercise caution when uploading the resulting support bundle to public sites as it contains detailed diagnostic information

I couldn’t find the file created from the file directory. Is there a exact location? I could find a temp folder but it’s empty. can you tell me how to locate the file created?

Hi @erandaind93,

The file should be at /tmp/bitnami-wordpress-info-20210406-085645-6372.zip, can you run the following command and check whether it outputs the filename:

ls /tmp/bitnami-wordpress-info-20210406-085645-6372.zip

If the file doesn’t exist, please try running the support too again.

Regards,
Francisco de Paz

Hi @fdepaz
Sent a message with gdrive link just now.

Hello,
Any update on this?

Hello @erandaind93,

Please try changing your Apache’s configuration at opt/bitnami/apache2/conf/bitnami/bitnami.conf to the following:

  # BEGIN: Support domain renewal when using mod_proxy without Location
  <IfModule mod_proxy.c>
    ProxyPass /.well-known !
  </IfModule>
  # END: Support domain renewal when using mod_proxy without Location
  # BEGIN: Enable HTTP to HTTPS redirection
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
  # END: Enable HTTP to HTTPS redirection
  # BEGIN: Enable non-www to www redirection
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} !^localhost
  RewriteCond %{HTTP_HOST} !^[0-9]+.[0-9]+.[0-9]+.[0-9]+(:[0-9]+)?$
  RewriteCond %{REQUEST_URI} !^/\.well-known
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]
  # END: Enable non-www to www redirection

Replacing your three rewrite rules for these two should solve the loop of redirections. The problem should be at the second RewriteRule that was redirecting to http://www.example.com. Although the condition %{HTTP:X-Forwarded-Proto} !https should be unnecessary as you already have %{HTTPS} !=on there is no harm leaving it there. After that, restart Apache running:

sudo /opt/bitnami/ctlscript.sh restart apache

Regards,
Francisco de Paz

Thanks for the reply.

I made the changes as per the last reply.
But the error still remains

Can you provide another solution pls

Hello @erandaind93,

There are several Apache’s errors related to PageSpeed and several plugins. Could you please disable PageSpeed following our Use PageSpeed With Apache guide and your plugins from the console as explained in Debug WordPress Errors.

After that, restart your instance and check whether the issue is solved. In the case the problem persists, please provide a new bnsupport report. If possible, please paste the code here.

Regards,
Francisco de Paz