kusumoto_teruya
kusumoto_teruya

Reputation: 2475

Redirect loop: Cloud Load Balancing to Compute Engine installed WordPress

When accessing Google Compute Engine with wordpress installed via Cloud Load Balancing from a browser, a redirect loop occurs.
Chrome returns ERR_TOO_MANY_REDIRECTS, and when I open the network inspector or Cloud Logging, I see that many 301s are running.

Configuration

What I tried

Other Information

How can I fix the redirect loop and access wordpress with the URL of the Load Balancer IP address?

enter image description here

enter image description here

Upvotes: 1

Views: 765

Answers (1)

John Hanley
John Hanley

Reputation: 81454

You have a typical setup with HTTP and HTTPS for the frontend and HTTP for the backend. This is called SSL offloading.

The problem is that your backend code is not detecting that the client connected to the load balancer using HTTPS. The HTTP header HTTP_X_FORWARDED_PROTO indicates the client connection protocol (HTTP/HTTPS).

This is easily fixed by editing the WordPress wp-config.php file and adding the following code at the bottom.

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
{
       $_SERVER['HTTPS'] = 'on';
}

X-Forwarded-Proto

Upvotes: 2

Related Questions