How to have Wordpress running on a subdirectory with an Nginx Proxy


Few months ago I had to set up a Blog for my startup accessART, which had a peculiar feature of be living at the /blog/en/ directory.
The main reason for using a directory instead of a subdomain is because of the SEO optimisation which I am going to write about pretty soon.

Unfortunately, I had to use Wordpress as we need some customisations that I didn't have time to write them for Ghost.

Anyway, main point was that I had to use one server for the website but I didn't want to pollute that server with Wordpress-related dependencies, such as PHP or MySQL.

That's where Nginx came to the rescue, as there is a great feature called proxying.

Thanks to that, I could proxy the blog setup from my /blog/en/ directory.

In theory, that should work great, but Wordpress can be a bitch.
(Maybe this is a very simple task for those who doesn't have any other technical challenges except Wordpress - however I consider that counter-intuitive)

Because of all the complex development of Wordpress, there are plenty of absolute URLs that simply doesn't allow me to use an existing template without find and replace all these usages + search on the DB.


On my main Nginx, the only thing I had to do was to proxy all the connections on a certain directory to a different server.

With a little of hacking with Nginx, I could manage to have it working:

    location /blog/en/ {
        try_files $uri @proxy;

    location @proxy {
        proxy_redirect off;
        proxy_set_header X-Forwarded-Host "$host";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://location-of-my-blog;

With that, I could manage to have it working without hacking onto the Wordpress code, and the only change I had to do on Wordpress side was literally configuring the Base URL to match my desired url: