Nginx路徑匹配規(guī)則小結(jié)
1.路徑配置的分類
在nginx中,一共有4種不同的路徑配置方法
= - Exact match
^~ - Preferential match
~ && ~* - Regex match
no modifier - Prefix match
#路徑完全一樣則匹配
location = path {
}
#路徑開(kāi)頭一樣則匹配
location ^~ path{
}
#正則匹配,大小寫敏感
location ~ path{
}
#正則匹配,大小寫不敏感
location ~* path{
}
#前綴匹配
location path{
}上面的執(zhí)行順序是,優(yōu)先查看Exact match,若存在,則停止。如不存在,則進(jìn)入Preferential match。之后在進(jìn)入Regex match,先看大小寫敏感的規(guī)則,再看大小寫不敏感的規(guī)則.最后進(jìn)入Prefix match.
= --> ^~ --> ~ --> ~* --> no modifier
在每一個(gè)同類型的匹配規(guī)則中,按照他們出現(xiàn)在配置文件中的先后,一一對(duì)比。
2.例子
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'
到此這篇關(guān)于Nginx路徑匹配規(guī)則小結(jié)的文章就介紹到這了,更多相關(guān)Nginx路徑匹配內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
配置Nginx以實(shí)現(xiàn)自動(dòng)重啟的方法
要實(shí)現(xiàn)Nginx的自動(dòng)重啟,我們通常會(huì)借助一個(gè)叫做systemd的工具,systemd是Linux系統(tǒng)中的一個(gè)服務(wù)管理器,它可以幫助我們管理系統(tǒng)的各種服務(wù),包括Nginx2025-02-02
nginx生成自簽名SSL證書配置HTTPS的實(shí)現(xiàn)
本文主要介紹在Nginx中生成自簽名SSL證書并配置HTTPS,包括安裝Nginx、創(chuàng)建證書、配置證書以及測(cè)試訪問(wèn),具有一定的參考價(jià)值,感興趣的可以了解一下2025-03-03
nginx報(bào)錯(cuò):[emerg] getpwnam(“www“)failed問(wèn)題及解決
這篇文章主要介紹了nginx報(bào)錯(cuò):[emerg] getpwnam(“www“)failed問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-03-03
ELK收集Nginx日志的項(xiàng)目實(shí)戰(zhàn)
本文主要介紹了ELK收集Nginx日志的項(xiàng)目實(shí)戰(zhàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
nginx 自定義 404、50x 錯(cuò)誤頁(yè)面的實(shí)現(xiàn)
本文主要介紹了nginx 自定義 404、50x 錯(cuò)誤頁(yè)面的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-12-12

