My environment is, a docker container running wordpress on apache can be accessed via ip:port
. The host environment has an apache instance which redirects traffic that comes to http://myurl
to localhost:port
using mod proxy (I have the same set up with other docker containers in the same host which is working fine). But accessing http://myurl
(after changing the wordpress config) will just redirect you to localhost (in the wordpress container's apache log i can see it giving a 301 to redirect you) .
The problem is only there when you access the base url. (http://myurl/wp-login.php works)
Host Apache config:
<VirtualHost *:80>
ServerName my.url.com
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</IfModule>
</VirtualHost>
This works (in wp-config.php
):
define('WP_HOME','http://8.8.8.8:8080');
define('WP_SITEURL','http://8.8.8.8:8080');
This doesn't
define('WP_HOME','http://my.url.com');
define('WP_SITEURL','http://my.url.com');
These are the wordpress plugins i have enabled. But note that i changed their configs accordingly as well.
UPDATE: This seems to have fixed the problem somewhat.
define('WP_HOME','http://8.8.8.8:8080');
define('WP_SITEURL','http://my.url.com');
Some of the components (home buttons etc) still go for the ip:port
but the system works.
Turns out the problem is the headers being stripped when the redirection happens. I fixed this by adding ProxyPreserveHost On
to the host apache configuration. The changed file looks like this now.
Host Apache config:
<VirtualHost *:80>
ServerName my.url.com
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPreserveHost On # needed if you need to pass the original host header
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</IfModule>
</VirtualHost>