色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:3日期:2023-08-03 20:13:38
目錄1. 對url的匹配1.1 默認匹配1.2 精確匹配( = )1.3 正則,區(qū)分大小寫 ( ~ )1.4 正則表達式,不區(qū)分大小寫 ( ~* )2. 匹配順序2.1 示例(精確匹配最高)2.2 示例(字串匹配次之)2.3 示例(正則匹間配高于通用匹配)2.4 示例(正則表達式間前邊的為準)2.5 示例(通用匹配兜底)3. 匹配間的沖突3.1 通用匹配 VS 字串匹配1. 對url的匹配1.1 默認匹配語法示例 location /crow/ { return 501 '通用匹配\n'; }1.2 精確匹配( = )語法示例 location = /crow/ { return 501 '精確匹配\n'; }1.3 正則,區(qū)分大小寫 ( ~ )語法示例 location ~ /crow/.*\.md { return 501 '正則表達式,區(qū)分大小寫\n'; }1.4 正則表達式,不區(qū)分大小寫 ( ~* )語法示例 location ~* /crow/.*\.md { return 501 '正則表達式,不區(qū)分大小寫\n'; }2. 匹配順序精確匹配(=)字串匹配(^~)正則匹配(~、~*)默認匹配()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 '正則表達式,區(qū)分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區(qū)分大小寫\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md精確匹配

可見精確匹配被匹配到。

下邊我們?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 '正則表達式,區(qū)分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區(qū)分大小寫\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問測試

如下可見,還剩 字串匹配、正則匹配、通用匹配,結果匹配到了 字串匹配。

[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 '正則表達式,區(qū)分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區(qū)分大小寫\n'; } #location ^~ /crow/test.md { # return 501 '字串匹配\n'; #}}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md正則表達式,區(qū)分大小寫2.4 示例(正則表達式間前邊的為準)

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

配置文件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 '正則表達式,不區(qū)分大小寫\n'; } location ~ /crow/.*\.md { return 501 '正則表達式,區(qū)分大小寫\n'; }}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md正則表達式,不區(qū)分大小寫2.5 示例(通用匹配兜底)

配置文件

我們還是將所有匹配都寫上

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 '正則表達式,區(qū)分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區(qū)分大小寫\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.txt通用匹配3. 匹配間的沖突3.1 通用匹配 VS 字串匹配

通用匹配和字串匹配相同時,啟動報錯

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

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

標簽: Nginx
主站蜘蛛池模板: 三级大片在线观看 | 2019国产精品 | 成人午夜看片在线观看 | 亚洲男人第一天堂 | 性感美女视频黄.免费网站 性高湖久久久久久久久 | 亚洲国产欧美在线成人aaaa | 911精品国产91久久久久 | 久草视频在线免费看 | 狠狠色狠狠色综合 | 国产短视频精品一区二区三区 | 久草久热 | 一区二区三区 亚洲区 | 国产在线一区二区三区欧美 | 15—17女人毛片 | 欧美一级特黄刺激爽大片 | 中国一级特黄剌激爽毛片 | 成人毛片免费观看视频 | 国产夫妇肉麻对白 | 最近中文在线中文 | 欧美理论大片清免费观看 | 国产99视频精品免费观看9e | 美女被cao免费看在线看网站 | 男女性生活网站 | 国产视频一二三 | 久草在线视频在线观看 | 1024手机基地在线看手机 | 免费人欧美成又黄又爽的视频 | 国产精品中文字幕在线观看 | 国产一级毛片亚洲久留木玲 | 国产欧美日韩不卡在线播放在线 | 亚洲炮网| 欧美成人小视频 | 欧美性一区二区三区 | 美女被免费网站在线软件 | 五月天婷婷伊人 | 亚洲美色综合天天久久综合精品 | 国产成人啪精品视频免费软件 | 一级欧美一级日韩毛片99 | 中国一级淫片aaa毛片毛片 | 亚洲欧美激情精品一区二区 | 亚洲国产精品国产自在在线 |