views:

36

answers:

1

Basically, the htaccess I use with apache says something like "if the requested file or directory does not exist, route the request through index.php"

How exactly can I do this with nginx?

That way, if a stylesheet is requested, it's served. But if the url isn't to a file on disk, then it should run the framework.

+1  A: 

The way I do this, is to ignore certain extensions...

The configuration bellow runs everything except gif/jpg etc... through modify.php

    location ~* \.(gif|jpg|jpeg|png|js|css|pdf)$ {
              root   /home/site/public_html;
            expires 365d;

    }

    location / {
        root   /home/site/public_html;
        index  index.php index.html index.htm;
        rewrite ^/(.*) /modify.php?file=$1;
            expires 5m;
    }

You can also test for the existance of a file with -f (though I prefer to avoid the extra stat call). The example bellow passes requests for missing files through to a proxy:

if (!-f $request_filename) {
  break;
  proxy_pass  http://127.0.0.1;
}
Eric