Nginx - Run website in subdirectory on different server

I have a website https://www.winni.in running in tomcat which is behind nginx and I also have a blog in wordpress which has url https://www.winni.in/blog both these are located on same machine in aws ec2

Due to some reason I want wordpress blog to be located on a separate ec2 instance which is also running nginx. But I don't want to change the url to subdomain like blog.winni.in, is there any way to do this? By which I can run blog on separate ec2 instance but keep using url as winni.in/blog?


You can use an Proxy in Nginx:

location / {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://YOURTOMCATSERVER:{PORT};
}

location /blog {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://YOURBLOGSERVER:{PORT};
}

You can consider using Nginx as a Reverse proxy for Tomcat & wordpress.

Add a seperate location tag for /blog/ & proxy pass that traffic to your new wordpress ec2 server. This will make sure that your URL stays at http://winni.in/blog/ & configure siteurl in wordpress to be http://winni.in and your nginx server's hosts file needs to make below entry

newEC2IPaddress winni.in