nginx location matching order

The Nginx server will first check whether there are common uri matches in multiple locations. If there are multiple matches, it will remember the one with the highest matching degree first. Then check the regular matching. Remember that the regular matching is in order, from top to bottom. Once the match is successful, the check will end, and the location block will be used to process the request. If all the regular matches fail, the request will be processed using the location block with the highest matching degree of common uri just recorded.

 

=

The location of the URI must exactly match the specified pattern. The pattern is limited here to a simple text string, and regular expressions cannot be used:

location = /abcd

This configuration statement:

Can match https://xxx/abcd (strict match)

Can match https://xxx/abcd?param1¶m2 (regardless of query string parameters)

cannot match https://xxx/abcd/ (ending slash)

cannot match https://xxx/abcde (add extra characters after the specified pattern)

 

^~

It can be understood that greedy matching is prohibited, because the normal matching rule is to match the string (except for the = match), so don't give up, you have to see if the regular can match, add the "^~" prefix , after matching the string, this rule is applied, and no longer see the regular.

 

~*

Case-insensitive regular matching.

location ~* ^/abcd$

This configuration statement:

Can match https://xxx/abcd (strict match)

Can match https://xxx/ABCD

Can match https://xxx/abcd?param1¶m2 (regardless of query string parameters)

cannot match https://xxx/abcd/ (because a regular expression is specified)

cannot match https://xxx/abcde (extra characters, regular mismatch)

 

~

The URI requested by the client that matches the specified regular expression must be case-sensitive.

location ~ ^/abcd$

This configuration statement:

Can match https://xxx/abcd (strict match)

cannot match https://xxx/ABCD (case sensitive)

cannot match https://xxx/abcd/ (because a regular expression is specified)

cannot match https://xxx/abcde (extra characters, regular mismatch)

 

null

When the matching prefix is ​​empty, the location of the URI must start with the specified pattern, and regular expressions cannot be used.

location /abcd

This configuration statement:

Can match https://xxx/abcd (strict match)

Can match https://xxx/abcd?param1¶m2 (regardless of query string parameters)

Can match https://xxx/abcd/ (ending slash)

Can match https://xxx/abcde (add extra characters after the specified pattern)

 

@

@是一个命名标记,这种location不会用于正常的请求,它们通常只用于处理内部的重定向(例如:error_page,try_file)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326270864&siteId=291194637