将apache重写转换为nginx重写

我有一个项目,我不得不将所有找不到的文件redirect到index.php。 我在apache中把.htaccess文件放在我的项目文件夹中。 该文件的内容是 –

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] 

现在我想在nginx中一样。 这里是我的nginx.conf的样子

 root /usr/local/apache2/htdocs; index index.php index.html index.htm; location /project/ { root /usr/local/apache2/htdocs; index index.php index.html index.htm; try_files $uri $uri/ index.php; } 

现在,每当我提出一个像http://localhost/project/hello这样的请求,那么这个请求应该去http://localhost/project/index.php但是这个说File not found

现在为什么我认为这将工作是因为位置块内的root指令覆盖块外的root指令(尽pipe值相同),重写模块将查找/usr/local/apache2/htdocs/project/index.php 。 我在这里错过了什么?

UPDATE

这个configuration工作

 root /usr/local/apache2/htdocs; location /project/ { index index.php index.html index.htm; #effectively root here is /usr/local/apache2/htdocs try_files $uri $uri/ /project/index.php; } 

但我不明白为什么这应该工作,因为正如在文档中指出的, 这里在位置块匹配的目录被附加到root指令的值

  location /project/ { root /usr/local/apache2/htdocs; index index.php index.html index.htm; - try_files $uri $uri/ index.php; + try_files $uri $uri/ /project/index.php; } 

也许你需要指定URL中的根? 否则,该URL没有参考点。 服务器无法猜测它上一次或用户打算的目录。 如果这样做没有达到你想要的,请回复评论,我会启动一个服务器来做一个快速testing。