在nginx中,一共有4种不同的路径配置方法
= - Exact match^~ - Preferential match~ && ~* - Regex matchno modifier - Prefix match
#路径完全一样则匹配 location = path { } #路径开头一样则匹配 location ^~ path{ } #正则匹配,大小写敏感 location ~ path{ } #正则匹配,大小写不敏感 location ~* path{ } #前缀匹配 location path{ }
如果存在精确匹配,则先执行精确匹配。如不存在,则进入Preferential match。之后在进入Regex match,先看大小写敏感的规则,再看大小写不敏感的规则.最后进入Prefix match.
= --> ^~ --> ~ --> ~* --> no modifier
在每一个同类型的匹配规则中,按照他们出现在配置文件中的先后,一一对比。
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'; }
/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'
以上就是Nginx路径匹配规则是什么的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号