国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:6日期:2023-08-03 20:13:38
目錄1. 對url的匹配1.1 默認匹配1.2 精確匹配( = )1.3 正則,區分大小寫 ( ~ )1.4 正則表達式,不區分大小寫 ( ~* )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 正則,區分大小寫 ( ~ )語法示例 location ~ /crow/.*\.md { return 501 '正則表達式,區分大小寫\n'; }1.4 正則表達式,不區分大小寫 ( ~* )語法示例 location ~* /crow/.*\.md { return 501 '正則表達式,不區分大小寫\n'; }2. 匹配順序精確匹配(=)字串匹配(^~)正則匹配(~、~*)默認匹配()2.1 示例(精確匹配最高)配置文件內容: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 '正則表達式,區分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區分大小寫\n'; } location ^~ /crow/test.md { return 501 '字串匹配\n'; }}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md精確匹配

可見精確匹配被匹配到。

下邊我們去掉精確匹配:

2.2 示例(字串匹配次之)配置文件內容: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 '正則表達式,區分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區分大小寫\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 '正則表達式,區分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區分大小寫\n'; } #location ^~ /crow/test.md { # return 501 '字串匹配\n'; #}}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md正則表達式,區分大小寫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 '正則表達式,不區分大小寫\n'; } location ~ /crow/.*\.md { return 501 '正則表達式,區分大小寫\n'; }}訪問測試[root@liubei nginx-crow-test]# curl http://localhost:1840/crow/test.md正則表達式,不區分大小寫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 '正則表達式,區分大小寫\n'; } location ~* /crow/.*\.md { return 501 '正則表達式,不區分大小寫\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指令(實戰示例匹配順序匹配沖突)使用詳解的詳細內容,更多關于nginx location指令的資料請關注好吧啦網其它相關文章!

標簽: Nginx
主站蜘蛛池模板: 在线中文字日产幕 | 国产成人亚洲精品一区二区在线看 | 久久男人的天堂色偷偷 | 91久久精品国产一区二区 | 99综合视频 | 亚洲国产成人精品一区91 | 狼人久久尹人香蕉尹人 | 九一色视频 | 亚洲免费视频网站 | 精品成人免费一区二区在线播放 | 国产成人精品日本亚洲网址 | 极品美女户外勾搭无套 | 欧美怡红院高清在线 | 久久久久免费精品视频 | 国产成人av在线 | 久草资源网 | 欧美视频在线一区二区三区 | 日本一级特黄毛片高清视频 | 亚洲欧洲无码一区二区三区 | 成人午夜在线 | 日本三级成人中文字幕乱码 | 香蕉视频国产精品 | 性欧美17一18sex性高清播放 | 国产高清在线精品一区a | 国产精品黄网站免费进入 | 国产乱子精品免费视观看片 | 性欧美久久 | 一级片免费观看视频 | 国产成人综合亚洲 | 狠狠色综合色综合网站久久 | 国内成人自拍 | 在线看黄网址 | 国产一区二区亚洲精品天堂 | 萌白酱国产一区 | 成人久久18免费网站游戏 | 99国产在线播放 | 99久久免费精品国产免费高清 | 精品特级一级毛片免费观看 | 最新亚洲精品 | 手机国产精品一区二区 | 波多野结衣一区在线观看 |