nginx location notes

Note LOCATION Nginx
= beginning exact matching
^ - represents the beginning 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 the regular case-insensitive matching
~ * represents the beginning of the regular case-insensitive match
! ~ And! ~ * Are case-sensitive and case-insensitive match does not match the regular
/ generic matches, will match any requests to.
A case where a plurality of matching location order is disposed (reference from, yet the actual verification, try to know, not rigidly stick, for reference only):
First Match =, followed by matching ^ ~, followed by file sequentially regular match, and finally handed / universal match. When there is a match success when stopped matching, processing requests by the current rule matches.
Example, the following matching rule:
<pre>
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 / {
# rules H
}
</ pre>

Then the effect of the following:
access the root directory /, such as http: // localhost / A matching rule will
access http: // localhost / login the matching rule B, http: // localhost / register matching rule is H
access HTTP: / /localhost/static/a.html matching rule 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 can not afford to rule role, and http: //localhost/static/c.png the priority rule 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 rule to match, 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

Guess you like

Origin www.cnblogs.com/newmiracle/p/11875317.html
Recommended