官方示例:http://nginx.org/en/docs/http/ngx_http_core_module.html#location

Let’s illustrate the above by an example:

location = / {
    [ configuration A ]
}

location / {
    [ configuration B ]
}

location /documents/ {
    [ configuration C ]
}

location ^~ /p_w_picpaths/ {
    [ configuration D ]
}

location ~* \.(gif|jpg|jpeg)$ {
    [ configuration E ]
}

The “/” request will match configuration A, 
the “/index.html” request will match configuration B, 
the “/documents/document.html” request will match configuration C, 
the “/p_w_picpaths/1.gif” request will match configuration D, 
and the “/documents/1.jpg” request will match configuration E.

中文解释:

=  优先级最高,只对当前目录或文件有限

^~ 优先级第二,不进行正则匹配,逐字符匹配

~ 区分大小写或 ~* 不区分大小写,优先级第三

/ 优先级最低,对当前目录及子目录有效