gbowe
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Dashboard etc. not obeying WP_HOME/WP_SITEURL??To any poor soul who finds themselves in the same situation:
There were a couple of keys for me to getting this working as expected.One: while copying the request headers, my proxy code was changing the
Hostheader to the internal host, and settingX-Forwarded-Hostto the original external Host value.
This doesn’t work, as it appears that WordPress uses the Host header value to form links on the admin dashboard and its various redirects, instead of constructing them from theWP_HOMEvalue, for some reason that continues to escape my understanding.
So I removed those two lines from my proxy code, meaning the host header of the internal request had the same value as the external request.
(I believe this is whatProxyPreserveHostdoes if you’re using apachemod_proxyas your reverse proxy, or if you’re using nginxproxy_passI think you sayproxy_set_header Host $http_host. I imagine this is also why things suggested to set$_SERVER['HTTP_HOST']to$_SERVER['HTTP_X_FORWARDED_HOST']in the wp config, but that didn’t correct WordPress’s behavior when I did that, it seemed to be happening after WordPress had already grabbed that value, so ymmv. Probably easier to do it on the proxy’s side than on WP’s.)Two: it complicated matters that the original external and resulting proxied internal urls differed by more than just the host but had a path,
/app/privateblog/{whatever}being just/{whatever}to WordPress. There isn’t really any use of or support for aX-Forwarded-Pathheader in the proxying world, so having a different path inside than outside is ice skating uphill if you can avoid it…
The easiest way to resolve this while still using the default WordPress image for the container was to just add an Alias in apache to serve the root’s content from the path as well.
So I added a file binding to the volumes of the privatewordpress in my compose yaml:- /pathonhost/000-default.conf:/etc/apache2/sites-available/000-default.confAnd the contents of
/pathonhost/000-default.confwas just copied from what the contents of that file is in the default WP image, with one line added before the closing </VirtualHost> tag:Alias '/app/privateblog' '/var/www/html' </VirtualHost>And then obviously I added the
/app/privateblogpath to the end of my configuration setting for what url to send all proxied requests to.With those changes, at least so far it seems to finally be working as expected.
I’d close this support topic, except that I’d still like to know: why does WordPress use the contents of the Host header to form these redirects and navigation links in the dashboard, instead of the
WP_HOMEvalue which it does use to form navigation links in the content?