Reputation: 389
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.
Upvotes: 2
Views: 2468
Reputation: 49702
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.
Upvotes: 4