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.

i'll need a bit of help for alias on folder with nginx

I have my folder www/ with the container of my site example.com and a lot of folder like client0, client1, client2... I should NOT modify www/example/ but i need that example.com/serveur0/ to be redirected to www/client0/

I made a nginx rule like this :

location /serveur0/ {
    alias /www/client0/;
    index index.php
    location ~ /serveur0/(.*\.php)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$1;
        include /etc/nginx/fastcgi_params;
    }
}

and it work perfectly. But i have some issues when i try to generalize it, using regex. I tried this

location /serveur([0-9]+)$/ {
    alias /www/client$1/;
    index index.php
    location ~ /serveur$1/(.*\.php)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$1;
        include /etc/nginx/fastcgi_params;
    }
}

And it doesn't work, and i fail to understand why. Could you help me?

EDIT : Full conf file available at http://pastebin.com/V5uGNkBV

share|improve this question

1 Answer 1

At the first location block:

  1. You forgot to specify a prefix ~ (or ~*) to use regular expressions.

  2. Remove the dollar sign ($) before the trailing slash.

location ~ /serveur([0-9]+)/ {
    alias /www/client$1/;
    index index.php
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        error_page 404 /error/404.php;
    }
}
share|improve this answer
    
Still doesn't work. My coworker want to hardcode hundred of locations in the file, and i don't want him to do that T_T –  Totobro Aug 9 '12 at 7:45
    
What did you get? error_log? –  quanta Aug 9 '12 at 7:48
    
You're talking about /var/log/nginx/error.log ? If so, there's nothing in. I emptied it, restarted the service and still doesn't work or display anything. –  Totobro Aug 9 '12 at 8:15
    
What did you get when access to /serveur1? Show the full config? –  quanta Aug 9 '12 at 8:25
    
I got a 404 not found error. The full config file is available on pastebin.com/V5uGNkBV –  Totobro Aug 9 '12 at 8:39

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.