nginx server block matching sequence

     When the client sends a http request, will be removed after receiving the header Nginx head host, matched with each server server_name nginx.conf in the order determined in the end of which a server to process the request block.

server_name match with host priority order:

Matching can be on the order of priority:
1, exact match
2, the front wildcard, such as * .xxxx.com
3, after such aaa.bbb. *
4, the regular matching, as ~ ^ \. Aaaa \ .bbb \ .com $
If the case does not match, the processing in the following two ways, priority is as follows:
1, the preferred default configuration items or listen to default_server
2, find the first block matching server listen port
 
Remarks:
1, nginx default_server of instructions may define a default server to deal with the request does not match any server_name, if not explicitly defined, defined by a first server will be selected as the default_server.
2, location syntax rules: location [=|~|~*|^~] /uri/ { … }

= It represents the beginning of an exact match

^~ Uri represents the beginning of a string beginning with a conventional, understood as the path to match the url

~ It represents the case-sensitive regular match

~* Indicate a case-insensitive regular match

!~And !~*are not case-sensitive and case-insensitive match does not match the regular

/ General match, any requests are matched.

If a matching rule to ^begin with, is the beginning of the string matches the specified path, if no match is content in the url contains the specified string

If a matching rule to $the end, is to match the specified string to the end of the path

A case where a plurality of matching location arranged order (time when there is a successful match, matching is stopped, according to the current processing request matching rule):

  1. Priority match =
  2. Next match ^~
  3. Performed in order to match the file
  4. Last match /

Guess you like

Origin www.cnblogs.com/xuzhujack/p/12343480.html