1

I wanted to add my blog, which is hosted in a different server, to my main website under subdirectory /blog.

The proxy through nginx went well

location /blog/ {
  proxy_pass http://107.170.8.156/;
}

I added also those lines to config.php

define( 'WP_SITEURL', '/blog' );
define( 'WP_HOME', '/blog' );

$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);

It works fine, however it fails to load css and js files errors

I searched everywhere on the Internet and I am not able to find any solution.

2
  • Are there any location directives on the main website which are intercepting all .css and .js URIs, perhaps to set the expiry? Commented Jun 29, 2016 at 7:31
  • yes, location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d; } Commented Jun 29, 2016 at 8:52

1 Answer 1

1

From your comment, you have something like this in your config file:

location /blog/ {
    proxy_pass http://107.170.8.156/;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { 
    expires 365d; 
}

The regex location will take precedence over the prefix location, and therefore, any URI ending with .css or .js will not be sent to the proxy.

You require any URI beginning with /blog/ to be sent to the proxy, irrespective of file extension. Use the ^~ modifier to cause the prefix location to take precedence over any regex location. Try:

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

See this document for details.

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

1 Comment

Richard that came up with a new issue. I am not able to login to the admin area. All the open sessions are still opened, but when I try to log in from any other device or browser, it redirects to the same page without any error messages.

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.