Get the App
SLTechnology News&Howtos  ›  Servers  › 

Example Analysis of matching rules in nginx

Shulou Source: shulou.com Published: 2022-06-01 13:29:27 09月28日 Update

Editor to share with you the example analysis of matching rules in nginx, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Nginx location

The equal sign type (=) has the highest priority and requires an exact match. Once the match is successful, no other matches are found.

^ ~ type expression. Once the match is successful, no other matches are found.

The regular expression type (~ *) takes second priority. If the regularities of multiple location can match, the one with the longest regular expression is used.

(location =) > (location full path) > (location ^ ~ path) > (location ~, ~ * regular order) > (location partial start path) > (/)

The problem of configuring proxy_pass path with / in nginx

The url accessed by the user is http://klvchen.com/abc/test.html

Eg:

# case 1: proxy_pass followed by / location / abc/ {proxy_pass http://klvchen.com/;} # will be represented as http://klvchen.com/test.html# case 2: after proxy_pass without / location / abc/ {proxy_pass http://klvchen.com;} # will be represented as http://klvchen.com/abc/test.html

Commonly used regularity

.: matches any character except the newline character

?: repeat 0 or 1 times

+: repeat 1 or more times

*: repeat 0 or more times

\ d: match the number

^: match the beginning of the string

$: the end of the matching string

{n}: repeat n times

{n,}: repeat n or more times

[C]: matches a single character c

[amurz]: matches any of the lowercase letters of amurz

The matching between parentheses () can be referenced later by $1, and $2 represents the content in the second () above. What is confusing in the rule is the escape of special characters.

The above is all the content of the article "sample Analysis of matching rules in nginx". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Regular character content more path article type expression example rule analysis success priority string case agent longest highest special accurate Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS Microsoft Shulou Tech Info NVidia