1

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

ErJab
  • 298
  • 4
  • 12

1 Answers1

1

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;
}
i.amniels
  • 325
  • 1
  • 4
  • 9