Research on the configuration and deployment of high performance Web server Nginx (16) Location matching mode priority

Source: Internet
Author: User

1 Location match 1.1 equals match: =

The Equals match is the equals sign, and the feature can be summed up as two points:

    1. Exact match
    2. Regular expressions are not supported
1.2 Null match character

The characteristics of an empty match are:

    1. Matches the URI starting with the specified pattern
    2. Regular expressions are not supported
1.3 Regular Match characters: ~

A regular match is a match that can be used with regular expressions. However, it should be emphasized that, in general, ~ it means:

区分大小写的正则匹配

and ~* said:

不区分大小写的正则匹配

But for some operating systems that are not case sensitive, there is no difference between the two. The other is ^~ that it represents a regular match that starts with the specified pattern.

1.4 Internal accessors: @

Commonly used for error pages, etc., this is not discussed.

2 match-Break precedence
  1. =
  2. Null match, when exact match is met
  3. ^~
  4. ~Or~*
  5. An empty match that satisfies the match at the beginning of the specified pattern

This is more abstract, let's take a look at an example.

2.1 Equals an empty match between match and exact match

Take a look at the following example (using the module we completed together previously Hello World ):

 location/poechant {Hello_world no1;} Location =/poechant {Hello_world no2;}  

If our request is http://my.domian/poechant , we found two location is matched to the requested URI, and according to our priority order, the first is an empty match when the exact match is matched, the second equals the match, so the second priority is high, which is the output:

hello_world, no2

It also indicates that Nginx's locatoin is not matched according to the order of writing in the configuration file.

2.2 The exact match of an empty match with a regular match ^~

In the following example, both begin to match exactly, and even this regular match is exact match.

location ^~ ^/poechant$ {    hello_world no1;}location /poechant {    hello_world no2;}

Which one does it match? You test it and you get:

hello_world, no2

is consistent with the order of precedence that we have mentioned above.

2.3 Instances of other matching priority comparisons

Slightly

-

Research on the configuration and deployment of high performance Web server Nginx (16) Location matching mode priority

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.