Understanding Nginx proxy_pass and url path translations

Consider the following nginx config blocks

location / {


location / {

They are both same in terms of final result. You if call /abc/def on the main server it passes the request to

But as soon as you have a location block with a non-root path like below

location /app {

The above config is not same as below

location /app/ {

Below table shows different combinations of the location and the proxy_pass url and the final path that the backend server will receive

Proxy Pass and Paths

Case # Nginx location proxy_pass URL Test URL Path received
1 /test1 /test1/abc/test /test1/abc/test
2 /test2 /test2/abc/test //abc/test
3 /test3/ /test3/abc/test /test3/abc/test
4 /test4/ /test4/abc/test /abc/test
5 /test5 /test5/abc/test /app1/abc/test
6 /test6 /test6/abc/test /app1//abc/test
7 /test7/ /test7/abc/test /app1abc/test
8 /test8/ /test8/abc/test /app1/abc/test
9 / /test9/abc/test /test9/abc/test
10 / /test10/abc/test /test10/abc/test
11 / /test11/abc/test /app1test11/abc/test
12 / /test12/abc/test /app2/test12/abc/test

Note: When you have a trailing / in the proxy_pass url then the url mentioned in the location block is removed from the actual url starting and rest of the pass is sent to the proxied server as seen in Case #4