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.

5
  • 1
    You've missed semicolon Commented May 24, 2016 at 13:50
  • 1
    And regexp should be ^/([^/]+) Commented May 24, 2016 at 13:55
  • 1
    Yeah, but only here ;) Doesn't change that 403. Commented May 24, 2016 at 13:56
  • 1
    And check the error.log. There should be mention of where nginx try to look for your files Commented May 24, 2016 at 13:57
  • Thanks for the regex correction. That pushed me a step ahead. And thanks for the advice to look in the error.log. Next I have to find a way how to rewrite the uri, couse nginx now looks at: /usr/share/nginx/html/app-one/public/app-one/index.html Commented May 24, 2016 at 14:12

1 Answer 1

5

Try this

location ~ ^/([^/]+)(.*)$ {
    alias   /usr/share/nginx/html/$1/public$2;
    index  index.html;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yep. That's it! Thank's a lot :)

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.