0

Is there an Nginx variable for the subpath inside the current location, or inside the current alias?

For example, given location /static {...} and GET /static/booze.png, is there a variable containing /booze.png, which would be the subpath inside the current location?

Or otherwise, given location /static { alias /srv/static-files; ...} and the same GET, is there a variable containing /booze.png, the subpath inside the current alias?

I know I can use regex locations to capture it, but I'd like to avoid it if I can use a builtin variable.

1 Answer 1

1

No, but you may try a trick like this:

location ~* /static/(.*)$ {
  set $subpath = $1;
}

The only thing you have to keep in mind - regexp locations have priority over regular ones.

1
  • A shorter and better way is to use/static/(?<subpath>.*)$ as the location regex. Then, $subpath can be used directly in the location block. Mar 9, 2015 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.