As Francis has already mentioned regex location is
location ~ ^/banniere…
But this will not work as you expect.
First nginx will match “location /”, then it will search regex
location inside this location and finally “location ~ .+.(js|”
will be used. Your solution:
Reviewing all my server definitions, I’m starting to imagine what a
nightmare could be, with on the first level a mix of standard prefix
location, ^~ and ~ ^/
I was also wondering wich has precedence for /images/foo.jpeg in these
case,
(I guess D, because ^/ before prefix shortcut regex)
location ~* .(gif|jpg|jpeg)$ {
[ configuration E ]
}
The request processing stops on the first matching regex.
Which is ?
I guess E, but I’m not sure since the doc doesn’t say if the inner regex
is
read before or after the next 1st level one. I understand that all first
level are evaluated to see if one branch need to be explored deeper, but
it’s not so obvious.
Anyway, this example is more a school case, it should be avoid in real
life,
so answer is not so important. If I need to answer such a question then
I’m
probably in the wrong way.
The $docs must stay as concise as possible, so I do not think Igorf
advice
should be there, even irf it is very interesting information, should be
there.
A ‘best practice/performance enhancement’ page could host it though.
That wriktten, I think that yes, the docs could be clearer, by
inserting:
"If the longest matching prefix location has the “^~” modifier then
regular
expressions are not checked. "
inside the third paragraph, which takes the process step-by-step but is
incomplete (one could understand every request processes regexes).
This sentence, isolated at the end of the section, produces a leap
backward
in the reasoning flow and loses the reader in his attempt to understand
how
things work. Definitely not user-friendly.
location ~* .(gif|jpg|jpeg)$ {
[ configuration E ]
}
Right. That is however exactly the example provided by the docs.
"If the longest matching prefix location has the “^~” modifier then
regular
expressions are not checked."
The regex is not even checked against the input request string.
[ configuration E ]
}
“Among [prefix locations], the location with the longest matching prefix
is
selected and remembered. Then regular expressions are checked, in the
order
of their appearance in the configuration file.”
The prefix string matches, it is remembered, but then the regex is
checked
and also matches.
“The search of regular expressions terminates on the first match, and
the
corresponding configuration is used.”
The request processing stops on the first matching regex.
location / {
location ~* .(gif|jpg|jpeg|svg|pdf)$ {
// static stuff not in /images/
[ configuration E ]
}
}
On Tue, May 6, 2014 at 8:39 PM, dcaillibaud [email protected]
wrote:
location ~* .(gif|jpg|jpeg)$ {
[ configuration E ]
}
The request processing stops on the first matching regex.
Which is ?
Every request is processed through one location block at the same
level.
Said otherwise, every time there is a choice to be made between several
location blocks, only one is picked up and entered. That process is
recursive.
In the provided example, there is only one regex at the root of the
tree.
Since the docs I quoted in my last message say that regexes have higher
precedence, then E will be taken over D if both match. The regex inside
the
prefix location ‘/images/’ has no impact/use in the current case since
it
is on the 2nd level of the tree, not its root, which was being
considered.
One step at a time :o)
Since regexes have higher precedence, and since it is prefered to use
prefix locations (because they are more ‘natural’ and efficient,
speaking
about performance), it is then advised either:
to avoid mixing prefix and regex locations on the same level, thus
encapsulating regex locations inside prefix ones first.
to use the ^~ operator to force prefix locations being taken over the
regex ones
B. R.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.