4.9.5 broke site behind load balancer, forwards to localhost [closed]

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');
  }