Nginx location Configuration Location plays an important role in nginx, processing the request string received by Nginx, such as address orientation, data cache, reply control, proxy forwarding, etc.
Location syntax
Location [=|~|~*|^~] URI {
...
}
The [] section is a match type, which can have no meaning:
(1) = Exact match, the request string must be identical to the URI when the match succeeds
(2) ~ Case-sensitive regular matching
(3) ~* case-insensitive regular match
(4) ^~ Note that this is not a regular match, which means that the URI starts with a normal string,
(5) Null means that the URI starts with a normal string and has the same meaning as the previous one, except that the matching order is different
Match type
(1) Normal match (no [] part, or specify ^~)
(2) exact match (=)
(3) Regular match (~ or ~*)
For example:
Location =/{
#精确匹配/, cannot take any strings after host name
...
}
Location/{
#普通匹配, because all addresses begin with/start, so this rule will match to all requests
...
}
Location ~* \. (Gif|jpg|jpeg) $ {
#正则匹配, this rule matches whether the URI ends in. gif or. jpg or. jpeg, not case-sensitive
...
}
Priority for multiple location
(1) To find the exact match, find and stop the match, execute this location
(2) Verify the common matching rules, whether there is a ^~ start match success, have, stop continuing to match, execute this location, no, note the highest matching the bar
(3) In order to verify the regular matching rules, there is a match, stop the continuation of matching, execute this location, otherwise perform the common matching rules of the highest matching the bar
Nginx location Configuration