1. 程式人生 > >Location詳解之精準匹配、正則匹配

Location詳解之精準匹配、正則匹配

location / {
            root   /usr/local/nginx/html;
            index  index.html index.htm;
        }


location ~ image {
           root /var/www/image;
           index index.html;
}


如果我們訪問  http://xx.com/image/logo.png
此時, “/” 與”/image/logo.png” 匹配
同時,”image”正則 與”image/logo.png”也能匹配,
正則表示式的成果將會使用.
圖片真正會訪問 /var/www/image/logo.png 



location / {
             root   /usr/local/nginx/html;
             index  index.html index.htm;
         }
 
location /foo {
            root /var/www/html;
             index index.html;
}
訪問 http://xxx.com/foo
 對於uri “/foo”,   兩個location的patt,都能匹配他們
即 ‘/’能從左字首匹配 ‘/foo’, ‘/foo’也能左字首匹配’/foo’,
此時, 真正訪問 /var/www/html/index.html 
原因:’/foo’匹配的更長
,因此使用之.;