[wp-hackers] Make WP more usable behind load balancers/proxies

Hauke mailman at haukebruno.de
Tue Oct 15 17:52:50 UTC 2013


Hi there,

is it possible to change code lines like

$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . 
$_SERVER['REQUEST_URI'] );

into something like this:

if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
  $serverhost = $_SERVER['HTTP_X_FORWARDED_HOST'];
} else {
   $serverhost = 'http://' . $_SERVER['HTTP_HOST'];
}
$current_url = set_url_scheme( $serverhost . $_SERVER['REQUEST_URI'] );

In my case I changed that in wp-admin/includes/class-wp-list-table.php 
(lines 494 and 651, WP 3.5.1 (same in WP 3.6.1).

I am not a developer, therefore that code isn't that nice. It's more like an 
idea for you guys with a lot more knowledge than mine.

The reason why I need that code:

We use WP (and some other apps) under one domain, e.g. example.com. 
In our case, we want to use (pseudo) subfolder domains for that different 
apps, e.g. 'example.com/blog', 'example.com/shop' or 'example.com/foo'. At 
the same time, we want to seperate these apps in one VHost per app (we 
use Apache + fcgid for separating PHP too).
So we put a load balancer/caching proxy (Varnish) in front of our 
webservers, which handles those URL rewriting stuff. It detects 
example.com/blog and rewrites the HTTP HOST Header Field to something 
internal like 'blog.example.local'. The Requests now reach the correct 
VHosts on the backend webservers. We provide the original hostname in 
the HTTP X_FORWARDED_HOST Header Field.
WP works good at all with that setting, but there are some things like 
pagination or that list table one the 'All Pages' site in the WP backend, 
that doesn't work because of producing URIs with the internal hostname.

-- 
Best regards,
Hauke


More information about the wp-hackers mailing list