Using WordPress Behind A Reverse Proxy
Read Time:50 Second

Using WordPress Behind A Reverse Proxy

WordPress is notoriously finicky with URL resolution. Using WordPress behind a reverse proxy can cause all sorts of issues. For instance, images and CSS won’t load. To fix this, add the code below to the top of the wp-config.php file in your WordPress installation:

define('.COOKIE_DOMAIN.', 'www.mydomain.com');
define('.SITECOOKIEPATH.', '.');

if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $list = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
        $_SERVER['REMOTE_ADDR'] = $list[0];
  }
define( 'WP_HOME', 'https://www.mydomain.com' );
define( 'WP_SITEURL', 'https://www.mydomain.com' );
$_SERVER['HTTP_HOST'] = 'www.mydomain.com';
$_SERVER['REMOTE_ADDR'] = 'https://www.mydomain.com';
$_SERVER[ 'SERVER_ADDR' ] = 'www.mydomain.com';

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
       $_SERVER['HTTPS']='on';

Make sure to replace each instance of www.mydomain.com with the domain of your WordPress website. Make sure to keep the <?PHP tag at the top of the wp-config.php file.

About Post Author

jon

Jon jokingly calls himself a tech-therapist. With more than a decade of experience in the tech industry as a technical analyst, it's his job to help people make sense of tech, implement logical solutions, and help take the fear out of using technology.

Leave a Reply

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

Waiting for FOR Loops To Finish In Javascript Previous post Waiting for FOR Loops To Finish In Javascript in 1 Easy Way!
Two Easy Ways To Record People Using Your Website (1) Next post 2 Easy Ways To Record People Using Your Website