location 匹配优先级 = / > = /login > ^~ /static/ > ~ .(gif|jpg|png|js|css) > ∗\.png > /
= 精确匹配
~ 区分大小写匹配
~* 不区分大小写匹配
^ 正则的开始
$ 正则的结束
匹配到就结束匹配
10 server{
11 listen 80;
12 server_name www.static.yoyo.com static.yoyo.com;
13 default_type "text/html";
14 location = / {
15 content_by_lua_block {
16 ngx.say("=/");
17 }
18 }
19 location = /login {
20 content_by_lua_block {
21 ngx.say("/login");
22 }
23 }
24 location ^~ /static/ {
25 content_by_lua_block {
26 ngx.say("^~/static/");
27 }
28 }
29 location ~ \.(gif|jpg|png|js|css)$ {
30 content_by_lua_block {
31 ngx.say("~\.gif|jpg|png|js|css");
32 }
33 }
34 location ~* \.png$ {
35 content_by_lua_block {
36 ngx.say("~*\.png$");
37 }
38 }
39 location / {
40 content_by_lua_block {
41 ngx.say("/");
42 }
43 }
44 }