Debugging `try_files` with 404 as a last resort

petecooper nginx-forum at forum.nginx.org
Wed Nov 14 01:30:08 UTC 2018


Francis Daly Wrote:
-------------------------------------------------------

> Do you know whether the file that corresponds to the url /index.php
> exists?
> 
> If it does exist, use
> 
>   try_files $uri $uri/ /index.php?$args;
> 
> If it does not exist, use
> 
>   try_files $uri $uri/ =404;

Hello Francis. Thank you for your reply.

I have some servers where the `index.php` exists, and some where it does not
exist. I have been using the approach you outlined above successfully where
I know `index.php` exists (or not), I think my question could perhaps be
worded: is there a `try_files` option where I can have $uri, then $uri/,
then `index.php` and finally `=404` if all else fails.
 
> http://nginx.org/r/try_files
> 
> The final argument to try_files is a uri or =code. "code" is
> returned. "uri" is searched for across all locations (due to an
> internal
> redirect).
> 
> The other arguments to try_files are files.

This is how I understood it, thank you for confirming!

> Does a file with the name $document_root/index.php?$args (expanding
> the
> two variables) exist? If not, processing will continue until the uri
> or
> =code at the end of the argument list.

I know the file `index.php` exists in the `root`. Would using the two
expanded variables in a log be sufficient to confirm Nginx can see it, or am
I missing something?

Thanks again, I am grateful for your time and assistance.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281938,281940#msg-281940



More information about the nginx mailing list