wordpress behind nginx proxy (acces from two sourc

2019-09-11 15:14发布

问题:

I had a hard search finding out how to get Word-press to show its page behind a proxy, i figured out a way to get the page-links and style-files loaded correctly, but the admin-pages throw 404 if i try to use anything within them. after rebuilding the docker-compose, admin-page works The current need to set WP_HOME and url, have the problem tat i can only decide if the page works in my network (by using the IP) or is reachable from the outside (by setting the url)

My change to the wp-config.php was to add:

define('WP_HOME','http://192.168.1.108/wordpress');
define('WP_SITEURL','http://192.168.1.108/wordpress');

the ngings location is:

location /wordpress/{
  proxy_buffering off;
  proxy_pass http://wordpress/;
  proxy_redirect default;
}

192.168.1.108 is the ip to reach nginx which uses the docker-container name "http://wordpress/" to reach wordpress.deleted some false entrys here

PS: This is basically a followup to docker running nginx as proxy to another webserver (on pi).

-- EDIT --: Some tests (and system restart) have changed some of tha above statements, they were changed to acomodate this, edits in bold.

-- EDIT 2--: I know one solution is to add the outside-URL to the hosts.txt (i use it on the device the site itself is running on) but tis wont help with mobile devices (which need to use both inside and ourtside IP).

-- EDIT 3--: Ok, now i managed to double my prepends whenever i try to enter a php generated page: I get http:///wordpress//wordpress/wp-admin/ same goes for comments. But login seems to work normal (altough it also is a php)?

回答1:

I think i have found the missing line (and i changed the IP to a name, which i entered to the host.txt)

the ngings location is:

location /wordpress/{
proxy_buffering off;
proxy_pass http://wordpress/;
proxy_redirect off;
}

(i am not sure if off is better than default)

My change to the wp-config.php was to add:

$_SERVER['HTTP_HOST']=$_SERVER['HTTP_X_FORWARDED_HOST'];
define('WP_HOME','http://<NAME>/wordpress');
define('WP_SITEURL','http://<NAME>/wordpress');

Also important: if testing inside a docker-compose make sure to clen it properly.