Home > Operation and Maintenance > Nginx > What are the Nginx path matching rules?

What are the Nginx path matching rules?

王林
Release: 2023-05-21 10:37:10
forward
3568 people have browsed it

1. Classification of path configuration

In nginx, there are 4 different path configuration methods

= - Exact match
^~ - Preferential match
~ && ~* - Regex match
no modifier - Prefix match

#路径完全一样则匹配
location = path {
}

#路径开头一样则匹配
location ^~ path{
}

#正则匹配,大小写敏感
location ~ path{
}

#正则匹配,大小写不敏感
location ~* path{
}

#前缀匹配
location path{
}
Copy after login

If an exact match exists, the exact match is performed first. If it does not exist, enter the Preferential match. After entering the Regex match, first look at the case-sensitive rules, then the case-insensitive rules. Finally, enter the Prefix match.

= --> ^~ --> ~ - -> ~* --> no modifier

In each matching rule of the same type, compare them one by one according to the order in which they appear in the configuration file.

2. Example

location /match {  
  return 200 'Prefix match: will match everything that starting with /match';  
}  
  
location ~* /match[0-9] {  
  return 200 'Case insensitive regex match';  
}  
  
location ~ /MATCH[0-9] {  
  return 200 'Case sensitive regex match';  
}  
  
location ^~ /match0 {  
  return 200 'Preferential match';  
}  
  
location = /match {  
  return 200 'Exact match';  
}
Copy after login

/match # => 'Exact match'
/match0 # => 'Preferential match'
/match2 # => ; 'Case insensitive regex match'
/MATCH1 # => 'Case sensitive regex match'
/match-abc # => 'Prefix match: matches everything that starting with /match'

The above is the detailed content of What are the Nginx path matching rules?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Error restarting nginx
From 1970-01-01 08:00:00
0
0
0
server - Nginx configuration webapp problem
From 1970-01-01 08:00:00
0
0
0
Nginx default.conf problem
From 1970-01-01 08:00:00
0
0
0
centos7 - NGINX exception occurs
From 1970-01-01 08:00:00
0
0
0
nginx load balancing
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template