Welcome! Log In Create A New Profile

Advanced

Re: try_files behaviour details

Maxim Dounin
August 16, 2010 07:08PM
Hello!

On Mon, Aug 16, 2010 at 04:07:41PM -0400, Ensiferous wrote:

> Hey,
>
> I have a question about how try_files works in some cases. The standard
> case seems to be
>
> server {
> server_name foo;
>
> location / {
> try_files $uri index.html;
> }
> }
>
> Here nginx tries $uri and then finally index.html if no other location
> block matches. Now say that there are no other location blocks and nginx
> enters location / again, the try_files directive is then skipped as it's
> already been used once, right?

No. In the example above nginx will enter location /, test $uri
existance, if not found - it will issue internal redirect to
fallback agument, "index.html" in this case.

As "index.html" (invalid uri, may only happen due to internal
redirects like the above) isn't matched by location / it will be
processed in default location context. With default root
("/usr/local/nginx/html") it will try to access
"/usr/local/nginx/htmlindex.html" file.

> Second example:
>
> server {
> server_name bar;
>
> try_files $uri index.php;
> }
>
> Here try_files is used in the server block. The wiki says try_files
> can't be used here but Nginx will happily accept it, from my testing it
> seems to behave identically to the first example except it's always
> executed. Is this a correct assumption?

In this example you define try_files in default location context,
the one which match both valid uris and "index.php".

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

try_files behaviour details

Ensiferous August 16, 2010 04:07PM

Re: try_files behaviour details

Maxim Dounin August 16, 2010 07:08PM

Re: try_files behaviour details

mike August 16, 2010 07:16PM

Re: try_files behaviour details

Ensiferous August 16, 2010 07:18PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 181
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready