2

My goal is to configure nginx to match locations dynamically like this:

http://www.domain.com/app-one
http://www.domain.com/app-two
http://www.domain.com/app-three

/usr/share/nginx/html/app-one/public
/usr/share/nginx/html/app-two/public
/usr/share/nginx/html/app-three/public

I'm confused how to do this. And if I can do it like this or if it's recommended or best practice to do something like this (I don't want to go the subdomain solution).

If I'm trying this:

location ~ /(^/)+ {
    alias   /usr/share/nginx/html/$1/public;
    index  index.html;
}

All I get is an 403.

But there's a way to handle that, right? Do you know how?

PS. Neither I found any explanation via google nor here that helps me.

Lars Schinkel
  • 711
  • 8
  • 16

1 Answers1

5

Try this

location ~ ^/([^/]+)(.*)$ {
    alias   /usr/share/nginx/html/$1/public$2;
    index  index.html;
}
Alexey Ten
  • 13,794
  • 6
  • 44
  • 54