Syntax rules: location [=|~|~*|^~]/uri/{...}
= The beginning indicates an exact match
The beginning of the ^~ indicates that the URI begins with a regular string and is understood to match the URL path. Nginx does not encode the URL, so the request is/STATIC/20%/AA and can be matched by the rule ^~/static//aa (note is a space).
~ starts with a case-sensitive regular match
~* begins with a case-insensitive regular match
/Universal match, any request will match to.
Multiple location configuration in the case of matching order for (resources, not actually validated, try to know, do not adhere to, for reference only):
First match =, second match ^~, followed by regular matching in file order, finally to/Universal match. When a match is successful, stop the match and process the request according to the current matching rule.
Dynamic resource access:
Location =/{
Proxy_pass Http://tomcat:8080/index
}
Static resource access configuration: (URL root path http://127.0.0.1/directory path corresponding to root)
#请求地址是http://127.0.0.1/images/1.jpg, new images directory in e:/nginx/
#location ~* \. (Gif|jpg|jpeg|png|css|js|ico) $ {
# root e:/nginx/;
#}
#请求地址是http://127.0.0.1/images/1.jpg, new images directory in e:/nginx/
Location ^~/images/{
Root e:/nginx/;
}
Reproduced from: http://cppmule.iteye.com/blog/1693593