Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Having set up multiple Kohana applications on Nginx, I need to adjust the "base url" parameter for each application. Before when I was using Apache with .htaccess this was easy (RewriteBase) but in Nginx I have found the following solution:

location /sites/site1/ {
    try_files $uri /sites/site1/index.php?$args;
}

location /sites/site2/ {
    try_files $uri /sites/site2/index.php?$args;
}

...etc...

Now, since I would like to add many more applications, I'd rather have a single location block passing the Kohana application to the correct path. I've tried something like this (this won't work for me):

location /sites/([a-z0-9\-]+)/ {
    try_files $uri /sites/$1/index.php?$args;
}

As you may see, I'm not a regex expert, but I want to pass any existing subdirectory with names containing alphanumerical characters and dash to the corresponding base path. Thanks.

share|improve this question

1 Answer 1

You need a prefix for location to do regex matching. Try this:

location ~* ^/sites/([a-z0-9\-]+)/ {
    try_files $uri /sites/$1/index.php?$args;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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