A little confused about trailing slash behavior in nginx

They are totally different.

In the first proxy_pass statement you have included a URI parameter with a value of /. In the second you haven’t.

When you give proxy_pass a URI parameter (within a prefix location), it transforms the requested URI similarly to the alias function, whereby the value of the location directive is substituted for the value of the URI parameter. For example /myapi/foo becomes /foo before being passed upstream.

If you do not provide proxy_pass with a URI parameter, no transformation takes place, and the request /myapi/foo is passed upstream unchanged.

See this document for details.

Leave a Comment