Skip to content

Instantly share code, notes, and snippets.

@reytech-dev
Created May 28, 2021 10:13
Show Gist options
  • Save reytech-dev/7bf85b81a76bd063c976bc9630ee1359 to your computer and use it in GitHub Desktop.
Save reytech-dev/7bf85b81a76bd063c976bc9630ee1359 to your computer and use it in GitHub Desktop.
Nginx location, proxy_pass path/subdir missing

NGINX location with proxy_pass

Example configuration

location /example {
  set $exampleVariable "examplePath";
  proxy_pass http://localhost:8080/$exampleVariable;
}

Example url

http://example.com/example/my/sub/dir

Expected behaviour

We expect the proxy_pass to request the uri "http://localhost:8080/$exampleVariable/my/sub/dir".

Actual behaviour

The proxy_pass uri looks like that "http://localhost:8080/$exampleVariable"

Why

Not found out so far, but based on the example above its clear, that a variable in the proxy_pass uri is causing the loss of the received location path.

Possible workarounds

  1. Don't use variables in your proxy_pass
  2. Update the location like that
location /example {
  set $exampleVariable "examplePath";
  rewrite ^\/example\/(.*)$ /$1 break;
  proxy_pass http://localhost:8080/$exampleVariable/$1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment