try_files and index

Edho Arief edho at myconan.net
Tue Jun 26 01:45:36 UTC 2012


On Tue, Jun 26, 2012 at 6:00 AM, whiskybar <nginx-forum at nginx.us> wrote:
> Why is it my first configuration returns 403 while my second
> configuration returns 404?
>
> I looked into logs and it seems my first configuration triggers the
> index module which is set to the default index.html, finds nothing and
> returns 403. Why isn't the =404 triggered? And why is the index module
> triggered at all?
>
> server {
>    root /var;
>    try_files $uri =404;
>    location / {
>    }
> }
>
> My second configuration works more like I expected; but then, why isn't
> the index module triggered as well? Does try_files disable the index
> module somehow?
>
> server {
>    root /var;
>    location / {
>        try_files $uri =404;
>    }
> }
>
> Can someone explain how nginx goes to decide what to do?
> Thank you
>

try_files doesn't trigger index; you must try $uri/ explicitly.
Therefore, the correct try_files you need is:
try_files $uri $uri/ =404;



More information about the nginx mailing list