Nested Locations Better???

Igor Sysoev igor at sysoev.ru
Sat Feb 12 23:54:21 MSK 2011


On Sat, Feb 12, 2011 at 03:47:22PM -0500, Dayo wrote:
> Igor Sysoev Wrote:
> -------------------------------------------------------
> > If you use only locations without regexes, then
> > you may not use nested
> > locations. nginx uses some kind of binary tree to
> > match locations, so
> > 
> >  location /set/subset/ { }
> >  location /set/ { }
> > 
> > are slightly faster than nested locations. BTW you
> > may write
> > 
> >  location /set/ { }
> >  location /set/subset/ { }
> > 
> > or
> > 
> >  location /set/subset/ { }
> >  location /set/ { }
> > 
> > - there is no difference for nginx: it finds the
> > longest match using
> > the tree. 
> 
> Understood. Thanks. I'll continue to order them as ...
> 
> location /set/subset/ { }
> location /set/ { }
> 
> ... just to maintain consistency with what I have done before.

Note, that order is important for locations with regex. And this is
causes configuraiton dependences. This is why I try to avoid regexes
or try to isolate them as nested locations inside usual locations.

> > The nested locations are better if you
> > had to use regex
> > locations. Then I usually isolate regex location
> > inside usual location:
> > 
> >  location /dir/ {
> >      location ~ ^/dir/(.+)$ {
> >          ...        
> >      }
> >  }
> 
> Got it. The example I was referring to had  ...
> 
> location ~ subset { }
> location ~ set { }
> 
> ... so I will nest them as per your indication in the original response


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list