I have a setup that is presented below:
domain_name -> nginx_ip_address -> wordpress_blog_ip_address
Where when a user visits "/blog", nginx forwards the request to a seperate ip address of a machine running a wordpress blog.
The problem is that when the user clicks on a post in the blog, the url will show as: "wordpress_blog_ip_address/post" and not "domain_name/blog/post". How can I fix this?
My current nginx file is below:
server {
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /blog {
proxy_pass http://new_ip_address/;
proxy_set_header Host $host;
}
}
It might be that wordpress is configured to use wordpress_blog_ip_address/
as a absolute url, and all url wordpress return will start with wordpress_blog_ip_address/
. To change this absolute url, in wp-config.php
, set WP_SITEURL
to be dynamically generated, i.e.:
define( 'WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/' );
and the same for WP_HOME
, WP_CONTENT_URL
, WP_PLUGIN_URL
and other field containing absolute url. ( use search feature in your editor. )
Source: https://codex.wordpress.org/Editing_wp-config.php#WordPress_address_.28URL.29
Another way to do it is by forcing Wordpress to output relative URL by using Relative URL plugin.