Nginx Location Matching rules:
Syntax rules: location [=|~|~*|^~]/uri/{...}
= Normal character Exact match, this priority is also the highest
~ Wavy line to perform a regular match, case-sensitive
~* indicates that a regular match is performed, is case-insensitive
^~ represents normal character matching, and if this option matches, matches only that option, and does not match the other options , typically used to match the directory
!~ indicates a case-insensitive match
!~* indicates a case-insensitive match
/generic match, any request will match to, default match
Location-matching Priority:
= Exact Match priority, if exact match is found, Nginx stops searching for other matches
^~ Next Match
The second is a regular match in the Order of the files, and finally a/generic match. When a match succeeds, the match is stopped and the request is processed according to the current matching rule.
For example:
Nginx configuration file: (omitting the previous general configuration)
Server { listen 80; server_name 127.0.0.1; #默认匹配 location / { echo "/"; } #精确匹配 location =/ { echo "=/"; } #精确匹配 location =/nginx { echo "=/nginx"; } #以gif结尾的区分大小写 location ~ \.gif$ { echo "GIF"; } #以gif结尾的不区分大小写 location ~* \.gif$ { echo "GIF"; } #匹配/static/Path location ^~ /static/ { echo "Static"; } access_log logs/tomcat1_access.log; }
Test:
# Curl 192.168.78.131=/# Curl 192.168.78.131/nginx=/nginx# Curl 192.168.78.131/123.gifgif# curl 192.168.78.131/123. gifgif# Curl 192.168.78.131/static/123.gifstatic
This article is from the "Baiyubao blog" blog, make sure to keep this source http://baiyubao.blog.51cto.com/2845008/1759223
Nginx-location Configuration