Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;


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

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


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.