2

I have a website and want to host a wordpress blog(hosted on a different instance) under '/blog'. I am using nginx proxy with below configuration

location ^~ /blog
    proxy_set_header   X-Real-IP            $remote_addr;
    proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
    proxy_set_header   Host                 $http_host;
    proxy_set_header   X-NginX-Proxy        true;
    proxy_set_header   X-Forwarded-Proto    $scheme;
    proxy_http_version 1.1;
    proxy_pass         11.111.11.111
    proxy_redirect     off;
  }

I have also modified wordpress settings->general

WordPress Address (URL) - http://mywebsite.com/blog

Site Address (URL) - http://mywebsite.com/blog

The '/blog' in not fully functional as it is unable to load css and js .

Anyone has any idea how to do this. I have read many posts on this issue , but none solved my issue. Thanks.

2
  • Is the blog hosted in the root of the other instance? Commented Sep 24, 2016 at 8:52
  • yes , its hosted on root of other instance Commented Sep 25, 2016 at 6:06

1 Answer 1

4

You are probably missing a mapping from the public URI /blog to the upstream URI /.

You can perform this function using the location and proxy_pass directives by appending a URI in the proxy_pass statement. See this document for details. For example:

location ^~ /blog/ {
    proxy_pass http://192.0.2.0/;
}

Depending on your overall configuration, the above may prevent the URL //example.com/blog (i.e. without a trailing /) from being correctly forwarded, in which case either (1) add a specific location block to handle the single case, or (2) add a rewrite ... break to the location block above.

Option (1) example (added to above):

location = /blog { rewrite ^ /blog/ last; }

Option (2) example:

location ^~ /blog {
    rewrite ^/blog(?:/(.*))?$ /$1 break;
    proxy_pass http://192.0.2.0;
}

In this second option, the aliasing function is moved to the rewrite statement, and the proxy_pass has no URI appended. See this document for details.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for late reply @RichardSmith. I tried your second method and it worked but some of the internal links are not working properly like 1) /wp-admin/post.php: instead publishing post ,its redirecting to /wp-admin/edit.php 2)Also wp-admin/edit-tags.php?taxonomy=category : is redirecting to /wp-admin/edit-tags.php Don't know why its causing redirection ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.