try_files php

Marcos Neves marcos.neves at
Thu May 27 22:13:32 MSD 2010

How can I reproduce this behavior:

with a request to /foo/bar

try file: foo/bar
try index.htm: foo/bar/
try file: foo/bar.htm
try file: foo/bar.html
try parse php: foo/bar.php
try file: /layout.htm
try file: /layout.html
try parse php: /layout.php
return 404 if not found.

I try this:

    location / {
      try_files $uri $uri/ $uri.htm $uri.html $uri.php layout.htm
/layout.html /layout.php;

Everything works, except PHP that returns as text file showing the source code.

ps: Is there a blog post that explain exactly how location, if,
rewrite and try_files works?
The docs are not so clear about how the flow works.

Marcos Neves

More information about the nginx mailing list