Nginx: location Quick Query

A, location parsed

Here Insert Picture Description

  • location is divided into three kinds:
    . 1) EXACT_MATCH: "=" type, fully matched;
    2) noregx: "^ ~" type, prefix match;
    . 3) REGEX: " " or " *" type, regular matching;
    . 4) the named : "@" type, inside jump match.

  • For paternity present location:
    1) the parent or regex noregex only type;
    2) can not named sub-type;
    3) promoter can not contain the parent name.

Two, location server class added clcf-> locations queue

Here Insert Picture Description

Third, establish a rapid query tree

  • ngx_http_init_locations
    . 1) of the server-class clcf-> locations sorted queue.
    exact_match / inclusive (name exact same previous)> regex (not sorted)> named (sorted)> noname
    2) portion, was added server level cscf-> named_locations array of named (queue);
    for REGEX (queue) portion, was added server level clcf-> regex_locations array.
    At this stage server clcf-> locations and only exact_match noregex type.

  • ngx_http_join_exact_locations
    If the same name exact_match inclusive type and the presence of queue locations, then merge the two nodes, namely: lq-> inclusive = lx-> inclusive ; the actual purpose of this step is to re-preparation for establishment sequence behind tree .

  • ngx_http_create_locations_list
    recursively each node location, get a list of the current node's name to its location prefix stored in the queue node * list field
    Here Insert Picture Description

  • ngx_http_create_locations_tree
    establish trigeminal balanced tree, the root node to intermediate locations, the left subtree is the left half of queue locations established location Tree, right subtree is the right half of the established location queue tree, tree root node for the the list queue to establish a tree.
    Here Insert Picture Description

Guess you like

Origin blog.csdn.net/u013032097/article/details/91422084
Recommended