av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

瀏覽:4日期: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 | 日韩电影中文字幕 | 日韩中文字幕在线观看视频 | 欧美色专区 | 在线免费亚洲视频 | 99reav | 久久久久九九九女人毛片 | 国产麻豆一区二区三区 | 国产高清在线观看 | 国产日韩精品在线 | 北条麻妃国产九九九精品小说 | 涩爱av一区二区三区 | 国产精品视频一区二区三区四蜜臂 | 日批的视频 | 91天堂 | 99国产精品久久久久老师 | 亚洲国产免费 | 日韩中文视频 | av片免费| 国产高清精品在线 | 欧美亚洲成人网 | 国产精品不卡一区 | 日韩国产欧美在线观看 | 麻豆久久久9性大片 | 精品国产18久久久久久二百 | 亚洲福利在线观看 | 日韩精品一区二区三区免费视频 | 国产激情在线 | 国产精品免费一区二区三区 | 欧美成人精品一区二区男人看 | 国产一区二区久久 | 精品国产伦一区二区三区观看体验 | 久久r精品 | 天天操人人干 | 欧美一区二区三区小说 | 日本一区不卡 | 亚洲国产网址 | 亚洲一二三视频 | 欧美日韩专区 | 国产日韩免费视频 | 国产精品久久久久久久7777 |