I have 2 wordpress web servers behind a load balancer. When updating from 4.9.4 to 4.9.5, these sites broke if accessed from the main domain (but continue to be accessible if I use their alternate addresses which is obvi not possible for our end users). Instead of the site loading by going to the main domain https://example.com, everyone who accesses the domain is instead directed to https://localhost. As I said, if someone accessed https://wp1.example.com or https://wp2.example.com, the sites work. For now, I have reverted to 4.9.4 which fixes the problem, but I would like to figure out a long term fix. Any suggestions?

FYI inside my wp-config files I am using these directives:

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);

UPDATE: I think I found the reason this is happening (https://core.trac.wordpress.org/changeset/42894) but still have no workable fix.

  • it's probably the defines in your wp-config.php that have done that, all it takes is a loopback request that also sets DB options. Are they really necessary? – Tom J Nowell Apr 4 '18 at 19:17
  • if it is the defines, how might I fix them and still respect multiple domain url access for my sites? (ie example.com as well as wp1.example.com) – Stephen Apr 4 '18 at 19:18
  • Did you try $_SERVER['SERVER_NAME']; instead of $_SERVER['HTTP_HOST'] Nice explanation: stackoverflow.com/a/2297421/1321398 – Pabamato Apr 4 '18 at 19:25
  • you should look into domain mapping plugins – Tom J Nowell Apr 4 '18 at 19:27
  • 1
    @Stephen it's server side config, you can have a diff/same one on each server, if your site right now is working for the WP_SITEURL value and the DB one, I believe it won't make a difference. The problem may be the value from the $_SERVER['HTTP_HOST']$_SERVER['HTTP_HOST'] constant – Pabamato Apr 5 '18 at 9:45

with some thanks to @Pabamato, I was able to work around this and update to 4.9.5 by changing my wp-config directives to:

define('WP_SITEURL', 'https://' . $_SERVER['SERVER_NAME']);
define('WP_HOME', 'https://' . $_SERVER['SERVER_NAME']);

And also adding a param to my nginx conf to properly account for variable server names:

fastcgi_param SERVER_NAME $host;

without both of the above, my particular setup would not work properly.

UPDATE: spoke too soon, all kinds of badly formatted page if connecting to load balancer, despite ssl insecure content fixer. Reverted to 4.9.4 and undid changes and problem went away. still looking for a complete solution...

UPDATE 2: I think I have finally isolated my last problems to being related to permalink issues. Clearing those this now all seems to work (at least in my test environment), so I will mark this as the solution after all.

UPDATE 3: I was wrong, clearing permalinks did not work, it only seemed like it did on my test site (test.example.com) where in fact it was working because all subdomains work (ie test.example.com, www.example.com, etc) whereas the main domain would NOT work no matter what I did. So forcing my site to always use www subdomain works, but sucks and I have no idea why still. In any event, here is my new code for wp-config that is working:

if($_SERVER['HTTP_HOST'] == 'wp1.example.com') {
    define('WP_SITEURL', 'https://wp1.example.com');
    define('WP_HOME', 'https://wp1.example.com');
  } else {
    define('WP_SITEURL', 'https://www.example.com');
    define('WP_HOME', 'https://www.example.com');

Not the answer you're looking for? Browse other questions tagged or ask your own question.