location [=|$|最长原则|^~](nginx-1.4.4)

优先级由上到下依次递减:

location =/a/1.png {
        return 400;
        }

 

        }
        location ~* \.png$ {
        return 403;
        }

 

        location /a/1.png {
        return 401;
        }

 

        location ^~ /a/ {
        return 402;
        }#^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录

 

        location /a/ {
        return 404;
        }
不测和上面402同时开启(会有充突)优先级无法比较!

 

 location / {
        return 500;
        }
#它的优先级别最低!

 注意:跟位置没并系!!!

server {
        listen       80;
        server_name  localhost;
        index index.html index.htm index.php;
        root /app/www/;
        location / {
        return 500;
        }
        location /a/ {
        return 404;
        }
#       location ^~ /a/ {
#       return 402;
#       }
        location /a/1.png {
        return 401;
        }
        location =/a/1.png {
        return 400;
        }
        location ~* \.png$ {
        return 403;
        }
        include /app/server/nginx/conf/rewrite/default.conf;
        access_log  /app/log/nginx/access/default.log;
}

 NB结论:(从右匹配!!!!)

结论:比较有意思是:/a/ 与 /  应该是 同种类型的匹配表达式, 可以从中得到,该匹配顺序是,将路径从“右匹配“, 可以推测形如逐个字符,那个先匹配到,就是那个优先。 因此得到是:/a/ 优先于 / .

 

posted @ 2016-07-20 15:40  bass  阅读(289)  评论(0编辑  收藏  举报