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 upgraded my nginx server from 0.7.x to 1.0.2 and I copied the old configuration file for the new nginx server. Everything worked fine, except for the if-directive. I had the following block of code in the old config file which doesn't seem to be working with the latest nginx version.

location /myapp {
         if (!-e $request_filename) {
                rewrite  ^/myapp/(.*)$  /myapp/index.php?q=$1  last;
                break;
          }
          root /var/www;
          index index.php index.html index.htm;
 }

Any idea what's wrong?

P.S.: Yes I know IfIsEvil and I did try exploring try_files, but I couldn't figure out how to pass only the part of the URI AFTER myapp/ as against passing the enter URI to index.php like so: try_files $uri index.php?q=$uri

share|improve this question

migrated from stackoverflow.com May 15 '11 at 7:28

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

up vote 1 down vote accepted

You want to redirect all requests to a common front controller.

location / {
    index index.php;
    try_files $uri $uri/ @handler; ## If missing pass the URI to front handler
}

location @handler {
    rewrite / /index.php;
    # Rewrite for @ErJab:
    # rewrite ^/myapp/(.*)$  /myapp/index\.php?q=$1  last;
}

location ~ .php$ { ## Execute PHP scripts 
    fastcgi_pass   127.0.0.1:9000;
}
share|improve this answer
    
You'd probably want to escape dot in regexp –  Alexander Azarov May 16 '11 at 12:43
    
@Alaz, tnx fixed it. –  i.amniels May 16 '11 at 13:10
1  
Not in rewrite, in the location's regexp: location ~ \.php$ –  Alexander Azarov May 16 '11 at 16:17
    
I have tested this config many times and it works :-) –  i.amniels May 18 '11 at 9:19
add comment

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.