Making WordPress work behind a reverse proxy

My current web infrastructure includes an LB that does SSL termination via pound and several web servers behind it. Unfortunately WordPress gets confused when dealing with this scenario and will serve, among others, images and CSS over HTTP, and text over HTTPS.

To get around this, all we have to do is edit wp-config.php and add the following code:

if ( (!empty( $_SERVER['HTTP_X_FORWARDED_HOST'])) ||
     (!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) ) {

    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
    $_SERVER['HTTPS'] = 'on';
}

Make sure to restart your web server!


Leave a comment

Leave a Reply

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