Search code examples
nginxproxypass

Nginx - proxy pass subpaths only


I would like to proxy the subpaths of my website to another service:

http://some-web-site.com/friends/ - renders /friends/index.html

http://some-web-site.com/friends/ [not empty request path] - proxy to another service.

Currently I have the following Nginx configuration:

location /programming/ {
   (...)
   proxy_pass http://tomcat:8080/friends;
}

But unfortunately this proxies /programming/ to http://tomcat:8080/friends.


Solution

  • Use an exact match location block to extract specific URIs for special handling:

    location = /programming/ {
        ...
    }
    location /programming/ {
        ...
        proxy_pass http://tomcat:8080/friends;
    }
    

    See this document for details.