try_files php
Igor Sysoev
igor at sysoev.ru
Thu May 27 23:24:21 MSD 2010
On Thu, May 27, 2010 at 04:14:38PM -0300, Marcos Neves wrote:
> How about this one?
>
> try_files $uri $uri/ $uri.htm $uri.html @php;
>
> location @php {
> rewrite ^.*$ $uri.php;
> }
You do not test laytout files here.
Here is the right configuration:
location / {
try_files $uri $uri/index.htm $uri.htm $uri.html @php;
}
location @php1 {
try_files $uri.php =404;
fastcgi_pass ...
}
> Do I need to put try files inside a location / { } ?
You should put it in most specific location.
> Is a good idea use: if (-f $uri.php) {do php handler}
No.
> Marcos Neves
> +55 44 9918-8488
>
>
>
> On Thu, May 27, 2010 at 4:04 PM, Igor Sysoev <igor at sysoev.ru> wrote:
> > On Thu, May 27, 2010 at 03:13:32PM -0300, Marcos Neves wrote:
> >
> >> 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.
> >
> > You can not mix different handlers: static and php, in one try_files.
> > My variant is similar to Merlin's:
> >
> > location / {
> > try_files $uri $uri/index.htm $uri.htm $uri.html @php;
> > }
> >
> > location @php1 {
> > try_files $uri.php @file1;
> the follow lines are always executed or only when the try_file above
> match $uri.php ?
Yes.
> > fastcgi_pass ...
> > }
> >
> > location @file1 {
> > try_files /layout.htm /layout.html @php2;
> > }
> >
> > location @php2 {
> What the =404 below means?
return 404 code as the last resort.
> > try_files /layout.php =404;
> > fastcgi_pass ...
> > }
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list