Dockerized WordPress

Dockerized ronniechung.com with minor problems. Nothing really to do with Docker itself though. The site is a WordPress blog and after I migrated it to Docker it was working fine. That is until I forced HTTPS with Let’s Encrypt and Nginx. The site would load but the CSS and JS wouldn’t, still being served over HTTP. So I thought this was a problem with the Nginx configuration, kept looking at it but didn’t see anything that would make this happen. Tried to login to the WordPress admin and got a “too many redirects” error. Searched for Nginx SSL too many redirects but didn’t seem to be the problem. Then I remembered I had to do something with WordPress when I first got it forced over SSL. Turns out the problem is with WordPress itself and the fix is to add the following to your wp-config.php file under the WP_DEBUG line:

if ( $_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’ )
{
   $_SERVER[‘HTTPS’]       = ‘on’;
   $_SERVER[‘SERVER_PORT’] = 443;
}

Apparently this is the same fix for CloudFlare too.

Leave a Reply

Your email address will not be published. Required fields are marked *