Quick question about try_files

Aaron Starr astarr at wiredquote.com
Sat Jan 8 00:27:32 MSK 2011


Maxim,

Thanks for your quick reply!

I should have included that in both cases, the default handler is this:

    location / {
      try_files $uri $uri/index.html @mongrel_app;
    }

And, there is no /archives/ handler. So, here are the snippets that I think
are relevant. Working:

    location ^~ /providers/ {
      error_page 404 = @archives;
      log_not_found off;
    }
    location @archives {
      rewrite "/providers/(.*)" /archives/providers/$1 last;
    }
    location / {
      try_files $uri $uri/index.html @mongrel_app;
    }

Not working:

    location ^~ /providers/ {
      try_files $uri /archives$uri @mongrel_app;
    }
    location / {
      try_files $uri $uri/index.html @mongrel_app;
    }

Also, I should mention that it in the not-working case, the behavior is that
it will correctly find the file in /providers/... but if the file is moved
to /archives/providers/..., it will no longer find it.

I've put all the location directives here: http://pastie.org/1438414

Thanks, again,

Aaron


On Fri, Jan 7, 2011 at 1:03 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Fri, Jan 07, 2011 at 11:41:06AM -0800, Aaron Starr wrote:
>
> > Hello, all.
> >
> > nginx version: nginx/0.7.67
> >
> > This works great to look first in fast local storage, and then fall back
> to
> > slower storage for older archives:
> >
> >     location ^~ /providers/ {
> >       error_page 404 = @archives;
> >       log_not_found off;
> >     }
> >     location @archives {
> >       rewrite "/providers/(.*)" /archives/providers/$1 last;
> >     }
>
> This rewrites to /archives/... and searches for location again.
> Request will be handled elsewhere, and it's not known how it will
> be handled from the config snippet provided.
>
> > I thought I could tidy this up by doing the following, but it doesn't
> work:
> >
> >     location ^~ /providers/ {
> >       try_files $uri /archives$uri @mongrel_app;
> >     }
> >
> > Anyone see why? Thanks in advance.
>
> This should work as long as root for archives matches one for
> providers.  But won't work as long as you have something like
>
>    location ^~ /archives/ {
>        root /path/to/another/storage;
>    }
>
> in your config.
>
> Maxim Dounin
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20110107/7908d173/attachment.html>


More information about the nginx mailing list