0

I have a nginx configuration that looks like this, where I serve different build versions at different paths. How can I do this using regex/wildcards? I need to be able to capture the path (PATH1, PATH2 etc.) as a variable and use it inside the alias directive as well.

    location /sitename/PATH1 {
      alias /some/fldr/PATH1;
      try_files $uri /sitename/PATH1/index.html;
    }

    location /sitename/PATH2 {
      alias /some/fldr/PATH2;
      try_files $uri /sitename/PATH2/index.html;
    }

    location /sitename/PATH3 {
      alias /some/fldr/PATH3;
      try_files $uri /sitename/PATH3/index.html;
    }
3
  • Does this answer your question? stackoverflow.com/questions/64188034/… Commented Oct 3, 2020 at 19:15
  • Is PATH1 string equal in location, alias and try_files directives? And PATH2 and PATH3 too? And /some/fldr/ path is the same in all three locations? Commented Oct 3, 2020 at 19:19
  • Yes, /some/fldr is the same in all three locations. The build for /sitename/PATH{X} lives in /some/fldr/PATH{X} Commented Oct 3, 2020 at 19:36

1 Answer 1

2

Check this:

location ~ ^/sitename/(?<path>PATH1|PATH2|PATH3)(?<subpath>/.*)? {
    alias /some/fldr/$path/;
    try_files $subpath /sitename/$path/index.html;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.