時間:2023-03-09來源:系統城裝機大師作者:佚名
在nginx中,一共有4種不同的路徑配置方法
= - Exact match
^~ - Preferential match
~ && ~* - Regex match
no modifier - Prefix match
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#路徑完全一樣則匹配 location = path { } #路徑開頭一樣則匹配 location ^~ path{ } #正則匹配,大小寫敏感 location ~ path{ } #正則匹配,大小寫不敏感 location ~* path{ } #前綴匹配 location path{ } |
上面的執行順序是,優先查看Exact match,若存在,則停止。如不存在,則進入Preferential match。之后在進入Regex match,先看大小寫敏感的規則,再看大小寫不敏感的規則.最后進入Prefix match.
= --> ^~ --> ~ --> ~* --> no modifier
在每一個同類型的匹配規則中,按照他們出現在配置文件中的先后,一一對比。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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'
/match1 # => 'Case insensitive regex match'
/MATCH1 # => 'Case sensitive regex match'
/match-abc # => 'Prefix match: matches everything that starting with /match'
到此這篇關于Nginx路徑匹配規則小結的文章就介紹到這了
2023-03-11
IDEA中的Tomcat中文亂碼問題2023-03-09
nginx配置客戶端保存cookie的實現2023-03-09
nginx https 443端口配置的方法1、 配置IIS 1.1 從開始打開服務器管理 1.2 添加角色和功能 1.3 添加角色和功能向導 1.4 按照如下步驟選擇 2、問題:缺少源文件解決方案...
2023-03-09
WHAT IS THE NGINX ? WHY WE USE NGINX? HOW TO USE NGINX ? Nginx有哪些應用? 動靜分離 反向代理 反向代理是什么? 反向代理的作用 配置反向代理 負載均衡 負載均衡是什么? 配置負載均衡 正向代理...
2023-03-09