Mixed content issue – Google managed SSL and Web Server SSL

Mixed content issue – Google managed SSL and Web Server SSL

Problem Description:

I’m currently using a Google managed SSL with a bitnami WordPress. The website has mixed content issue. The media library is still using http://

Since I’m using Google mananged SSL, I can’t set up a SSL(Let’sEncrypt) on the server because the domain is resolved to the load balancer’s IP.

It will break the site if I change

define( 'WP_HOME', 'http://example.com' );    
define( 'WP_SITEURL', 'http://example.com' );

to

define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );

What can I do here to resolve the mixed content issue?

Solution – 1

The problem is that WordPress is not detecting that users connected to the load balancer using HTTPS. You have configured the load balancer to connect to your backend using http, which is recommended, but WordPress does not know that.

Add the following to wp-config.php. Then you can start using https for your WordPress configuration.

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

Note: This will fix mixed content issues except those that were caused by the above configuration issue.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject