I have a simple user based storage for images where I have a main folder say 'users' and within it, my server creates variable folders to store images for each user. The string used for the folder is randomly generated. What I would like is to designate the random string on the path as a variable.

here is an example

say root /myapp

then within /myapp/users/ there are /user1 /user2 /user3 ... so on

I would like the expression to go something like location /users/{{variableUser}}/cover

1 Answer 1


See this question on superuser: https://superuser.com/questions/330194/how-to-i-get-variables-from-location-in-nginx

Basically, you use regular expressions and capture the variable you need in your location block:

location ~ /users/([a-z0-9]+)/cover {
  # your "random string" will be captured in a variable named $1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .