I had put the first location block on top so that it would be processed
since both would match but now wondering if the nested version is more
efficient.
I had been under the impression that nested locations were to be avoided
but seeing Igor writting the code in that manner got me wondering.
Is it better to have them all independent as I had originally shown were
Nginx would match against the two in some cases and then choose the
closest match out of the two, or the second, nested version where it
will always match the broader location and then sometimes also match the
tighter location inside?
On Sat, Feb 12, 2011 at 02:33:31PM -0500, Dayo wrote:
[/code]
will always match the broader location and then sometimes also match the
tighter location inside?
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. The nested locations are better if you had to use regex
locations. Then I usually isolate regex location inside usual location:
You may use it, but do not see any advantage: you
still have unisolated
configuration dependences.
I see. Seems to me that there is likely to be limited benefit in nested
two regex based locations as well and that the main potential advantage
would be static and then regex. Is this correct?
Now that I have the debug compiled in, I’ll try looking there to see how
things flow as well.
On Sat, Feb 12, 2011 at 03:47:22PM -0500, Dayo wrote:
are slightly faster than nested locations. BTW you
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.
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