亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

nginx?location指令(匹配順序匹配沖突)實(shí)戰(zhàn)示例詳解

瀏覽:5日期:2023-08-03 20:13:38
目錄1. 對(duì)url的匹配1.1 默認(rèn)匹配1.2 精確匹配( = )1.3 正則,區(qū)分大小寫(xiě) ( ~ )1.4 正則表達(dá)式,不區(qū)分大小寫(xiě) ( ~* )2. 匹配順序2.1 示例(精確匹配最高)2.2 示例(字串匹配次之)2.3 示例(正則匹間配高于通用匹配)2.4 示例(正則表達(dá)式間前邊的為準(zhǔn))2.5 示例(通用匹配兜底)3. 匹配間的沖突3.1 通用匹配 VS 字串匹配1. 對(duì)url的匹配1.1 默認(rèn)匹配語(yǔ)法示例 location /crow/ { return 501 '通用匹配\n'; }1.2 精確匹配( = )語(yǔ)法示例 location = /crow/ { return 501 '精確匹配\n'; }1.3 正則,區(qū)分大小寫(xiě) ( ~ )語(yǔ)法示例 location ~ /crow/.*\.md { return 501 '正則表達(dá)式,區(qū)分大小寫(xiě)\n'; }1.4 正則表達(dá)式,不區(qū)分大小寫(xiě) ( ~* )語(yǔ)法示例 location ~* /crow/.*\.md { return 501 '正則表達(dá)式,不區(qū)分大小寫(xiě)\n'; }2. 匹配順序精確匹配(=)字串匹配(^~)正則匹配(~、~*)默認(rèn)匹配()2.1 示例(精確匹配最高)配置文件內(nèi)容:server { listen 1840; root /usr/share/nginx/html; location / {index index.html index.php index.htm; } location /crow/ { return 501 '通用匹配\n'; } location = /crow/test.md { return 501 '精確匹配\n'; } location ~ /crow/.*\.md { return 501 '正則表達(dá)式,區(qū)分大小寫(xiě)\n'; } location ~* /crow/.*\.md { return 501 '正則表達(dá)式,不區(qū)分大小寫(xiě)\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問(wèn)測(cè)試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md精確匹配

可見(jiàn)精確匹配被匹配到。

下邊我們?nèi)サ艟_匹配:

2.2 示例(字串匹配次之)配置文件內(nèi)容:server { listen 1840; root /usr/share/nginx/html; location / {index index.html index.php index.htm; } location /crow/ { return 501 '通用匹配\n'; } #location = /crow/test.md { # return 501 '精確匹配\n'; #} location ~ /crow/.*\.md { return 501 '正則表達(dá)式,區(qū)分大小寫(xiě)\n'; } location ~* /crow/.*\.md { return 501 '正則表達(dá)式,不區(qū)分大小寫(xiě)\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問(wèn)測(cè)試

如下可見(jiàn),還剩 字串匹配、正則匹配、通用匹配,結(jié)果匹配到了 字串匹配。

[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md字串匹配2.3 示例(正則匹間配高于通用匹配)配置文件server { listen 1840; root /usr/share/nginx/html; location / {index index.html index.php index.htm; } location /crow/ { return 501 '通用匹配\n'; } #location = /crow/test.md { # return 501 '精確匹配\n'; #} location ~ /crow/.*\.md { return 501 '正則表達(dá)式,區(qū)分大小寫(xiě)\n'; } location ~* /crow/.*\.md { return 501 '正則表達(dá)式,不區(qū)分大小寫(xiě)\n'; } #location ^~ /crow/test.md { # return 501 '字串匹配\n'; #}}訪問(wèn)測(cè)試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md正則表達(dá)式,區(qū)分大小寫(xiě)2.4 示例(正則表達(dá)式間前邊的為準(zhǔn))

上例中我們看到:~在前邊,因此先匹配了 ~。如果我們把~和~*換個(gè)位置

配置文件server { listen 1840; root /usr/share/nginx/html; location / {index index.html index.php index.htm; } location /crow/ { return 501 '通用匹配\n'; } location ~* /crow/.*\.md { return 501 '正則表達(dá)式,不區(qū)分大小寫(xiě)\n'; } location ~ /crow/.*\.md { return 501 '正則表達(dá)式,區(qū)分大小寫(xiě)\n'; }}訪問(wèn)測(cè)試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md正則表達(dá)式,不區(qū)分大小寫(xiě)2.5 示例(通用匹配兜底)

配置文件

我們還是將所有匹配都寫(xiě)上

server { listen 1840; root /usr/share/nginx/html; location / {index index.html index.php index.htm; } location /crow/ { return 501 '通用匹配\n'; } location = /crow/test.md { return 501 '精確匹配\n'; } location ~ /crow/.*\.md { return 501 '正則表達(dá)式,區(qū)分大小寫(xiě)\n'; } location ~* /crow/.*\.md { return 501 '正則表達(dá)式,不區(qū)分大小寫(xiě)\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問(wèn)測(cè)試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.txt通用匹配3. 匹配間的沖突3.1 通用匹配 VS 字串匹配

通用匹配和字串匹配相同時(shí),啟動(dòng)報(bào)錯(cuò)

配置文件 location /crow/test.md { return 501 '通用匹配\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }啟動(dòng)報(bào)錯(cuò)如下:nginx-crow-test | nginx: [emerg] duplicate location '/crow/test.md' in /etc/nginx/conf.d/default.conf:45

以上就是nginx location指令(實(shí)戰(zhàn)示例匹配順序匹配沖突)使用詳解的詳細(xì)內(nèi)容,更多關(guān)于nginx location指令的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Nginx
主站蜘蛛池模板: 免费观看一级特黄欧美大片 | xxxxx大片在线观看 | 国产乱码精品一区二区三区卡 | a一级日本特黄aaa大片 | 国产萝控精品福利视频免费观看 | 免费特黄一级欧美大片 | 国产黄a三级三级看三级 | 青青青国产精品国产精品美女 | 欧美黑人性大免费高清视频 | 国产美女网站视频 | 国产a免费视频 | 亚洲已满18点击进入在线观看 | 久久er精品视频 | 久久久久国产成人精品 | 亚洲综合激情另类图片专区 | 首页亚洲国产丝袜长腿综合 | 香蕉在线视频网站 | 婷婷成人综合 | 在线观看国产精美视频 | 欧美专区一区二区三区 | 久久国产乱子伦精品免费一 | 久草在线国产视频 | 中文字幕在线观 | 国产拍| 看片在线观看免费 | 日日噜噜夜夜狠狠tv视频免费 | 国产剧情演绎在线 | www.国产精品.com | 免费一级毛片在线播放傲雪网 | 色婷婷国产| 毛片线看免费观看 | a级毛片免费播放 | 国产精品福利视频萌白酱g 国产精品福利影院 | 欧美在线网站 | 国产成人一区二区三区高清 | 久久综久久美利坚合众国 | 国产在线每日更新 | 色婷在线 | 一级美国乱色毛片 | 久久成人18 | 香蕉视频在线视频 |