location [=|~|~*|^~] /uri/ { … }
= Exact matching at the beginning of
~ ^ Represents the beginning of the uri string beginning with a conventional, is understood to match the path to the url. url do not nginx coding, so the request is / static / 20% / aa, may be regularly ^ ~ / static / / aa matched (note the space).
~ Represents the beginning of a case-sensitive match regular
~ * Represents the beginning of a case-insensitive regular match
! ~ And! ~ * Are case-sensitive and case-insensitive match does not match the regular
/ Generic matches, any requests are matched.
Access to the root directory /, such as http: // localhost / A will match rule
Visit http: // localhost / login will match rule B,
HTTP: // localhost / H the Register the matching rules
Visit http: //localhost/static/a.html rule will match C
Visit http: //localhost/a.gif, http: //localhost/b.jpg the matching rules D and E rules, but the rules of the order of precedence D, E does not work rules, and http: // localhost / static / c .png precedence rules to match C
Visit http: //localhost/a.PNG the matching rules E, without matching rules D, E because the rules are not case sensitive.
Visit http: //localhost/a.xhtml not match the rules and regulations F G, http: //localhost/a.XHTML not match rule G, because it is not case-sensitive. Rules F, G belongs to the exclusion rule, but does not meet the matching rules match
with that, so think about practical applications where it would be used.
Visit http: // localhost / category / id / 1111 then the final match to rule H, because the above rules do not match, this time should be nginx forward the request to the back-end application server, such as FastCGI (php), tomcat (jsp ),
nginx proxy server as the direction of existence.
LOCATION = / {
# Rule A
}
LOCATION = / Login {
# Rule B
}
LOCATION ^ ~ / static / {
# Rule C
}
LOCATION ~ \. (GIF | JPG | PNG | JS | CSS) $ {
# rule D
}
LOCATION * ~ \ .png $ {
# rule E
}
LOCATION! ~ \ .xhtml $ {
# rule F.
}
LOCATION! ~ * \ .xhtml $ {
# rule G
}
LOCATION / {
# rule H
}