Reputation: 2475
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.
X-Forwarded-Proto
header.How can I fix the redirect loop and access wordpress with the URL of the Load Balancer IP address?
Upvotes: 1
Views: 765
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';
}
Upvotes: 2