Search code examples
nginxnginx-reverse-proxynginx-location

Reverse proxy: forward all requests to sub-path of upstream app


I am using Nginx as a reverse proxy.

I have an upstream call app_demo. How do I route all incoming requests to the upstream using a sub-path as root? For example, if the incoming is to /page1, it should be forwarded to /module1/page1 in the upstream app. That is, all incoming paths will be "rooted" at /module1 in the upstream. All /* goes to /module1/*.

Is such a configuration possible?

app_demo is fully functional web site, serving a bunch of pages, from its root as well as via a path under /module. So for example, app_demo would serve the following urls:

/welcome
/aboutus
/contactus
/module/page1
/module/page2

Basically, I want the server currently being configured in nginx to see only the urls under /module1/ and not to be able to access /welcome, /aboutus, etc.


Solution

  • Try this:

    location / {
        proxy_pass http://app_demo/module1/;
    }