0

I have two servers

  1. http://example.net - my "main" server
  2. http://example.com - a server dedicated to my blog

both servers run Nginx on Ubuntu 14.04. I have cofigured the example.net server thus

location /blog {
 proxy_pass https://ip.of.example.com/blog;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
}

Now when I browse to https://example.net/blog the blog landing page on the example.com server is displayed. However, this is happening at the expense of a redirect to the example.com server so the browser address bar ends up showing https://example.com/blog/path/to/article in place of https://example.net/blog/path/to/article.

Quite apart from the fact that this is not the desired result having blog content appearing on another domain would have disastrous SEO consequences.

I am afraid I am working in the dark here since I understand little of Nginx reverse proxy configuration. I'd be most grateful to anyone who might be able to help out.

0

I have spent the best part of a day trying to figure this out. So here is the answer for anyone running into this post. The point here is making sure that you ask the right question. Nginx configurations are remarkably logical so the problem is not there. The problem is more with the way Wordpress deals with things. To fix the issue I eventually edited the wp-config.php file and added

$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
define('WP_HOME', 'https://example.net/blog');
define('WP_SITEURL', 'https://example.net/blog');

With this edit - and the Nginx configuration for example.net in my original question everything works perfectly. Hopefully, this answer will spare someone else the frustration and the expensive loss of time that I have had to endure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.