Location expression type
~ indicates that a regular match is performed, case-sensitive
~* indicates that a regular match is performed, is case-insensitive
^~ indicates normal character matching. Match with prefix. If the match succeeds, the other location is no longer matched.
= Exact Match of ordinary characters. Which is exactly the same.
@ It defines a named location, used when directed internally, such as Error_page, Try_files
Location-Priority Description
The order of location in Nginx location and configuration is not much related. The type of the positive location expression. Expressions of the same type, long strings will match first.
Here are the instructions by priority:
The equals type (=) has the highest precedence. Once the match succeeds, no other matches are found.
An ^~ type expression. Once the match succeeds, no other matches are found.
The priority of the regular expression type (~ ~*). If more than one location has a regular match, the longest regular expression will be used.
The regular string match type. Match by prefix.
Location Priority Example
The configuration entries are as follows:
Location =/{
# just match the request/
[Configuration A]
}
Location/{
# matches all requests that begin with/.
# But if you have a longer expression of the same type, select a longer expression.
# If there are regular expressions that can match, the regular expression is matched first.
[Configuration B]
}
location/documents/{
# matches all requests that begin with/documents/.
# But if you have a longer expression of the same type, select a longer expression.
# If there are regular expressions that can match, the regular expression is matched first.
[Configuration C]
}
Location ^~/images/{
# matches all expressions beginning with/images/and stops matching lookups if the match succeeds.
# So, even if there is a matching regular expression location, it will not be used
[Configuration D]
}
Location ~* \. (Gif|jpg|jpeg) $ {
# matches all requests ending in GIF jpg jpeg.
# But a request that begins with/images/will use the Configuration D
[Configuration E]
}
Request Matching Sample
/-Configuration A
Configuration B/index.html
/documents/document.html, Configuration C
/images/1.gif, Configuration D
/documents/1.jpg, Configuration E
Note that the above matches are independent of the order defined in the configuration file.
Free pick up Brother Lian IT Education Original Linux Operations Engineer video/Detailed Linux tutorials, details of the website customer service: http://www.lampbrother.net/linux/
or hooking up with Q2430675018.
Welcome to the Linux Communication Group 478068715
The priority of NGINX location in the configuration