location matching command
~ #The wavy line means performing a regular match, case-sensitive
~* #Indicates performing a regular match, case-insensitive
^~ #^~ means normal character matching, if the option matches , only matches this option and does not match other options. It is generally used to match directories
= #Exact matching of ordinary characters
@ #"@" Defines a named location, used for internal orientation, such as error_page, try_files
The priority of location matching (regardless of the order of locations in the configuration file)
= Exact matches will be processed first. If an exact match is found, nginx stops searching for other matches.
Ordinary character matching, regular expression rules and long block rules will be prioritized for query matching, which means that if the item matches, you need to check whether there are regular expression matches and longer matches.
^~ will only match this rule, and nginx will stop searching for other matches, otherwise nginx will continue to process other location instructions.
Finally match the instructions with "~" and "~*". If a corresponding match is found, nginx stops searching for other matches; when there is no regular expression or no regular expression is matched, then the matching degree is the highest The verbatim matching directive will be used.
location priority official document
For example
location = / { # 只匹配"/". [ configuration A ] } location / { # 匹配任何请求,因为所有请求都是以"/"开始 # 但是更长字符匹配或者正则表达式匹配会优先匹配 [ configuration B ] } location ^~ /images/ { # 匹配任何以 /images/ 开始的请求,并停止匹配 其它location [ configuration C ] } location ~* \.(gif|jpg|jpeg)$ { # 匹配以 gif, jpg, or jpeg结尾的请求. # 但是所有 /images/ 目录的请求将由 [Configuration C]处理. [ configuration D ] }
The above introduces the nginx location matching rules, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.