Home >Backend Development >PHP Tutorial >Nginx location syntax configuration detailed explanation location meaning $location location reset
location means "positioning" and can be positioned differently according to the URI.
is essential in the configuration of the virtual host. Location can position different parts of the website to different locations. In terms of processing method, the syntax of
location
location [=|~|~*|^~] patt {
}
location statements can be roughly divided into three typeslocation = demo { } [Exact matching]
location demo {} [Normal matching]
location ~ demo {} [Regular matching]
In these three types of matching, precise matching is given priority. If the precise matching is successful, the matching process is stopped
The beginning oflocation = / { # 精确匹配 / ,主机名后面不能带任何字符串 config A } location / { # 因为所有的地址都以 / 开头,所以这条规则将匹配到所有请求 # 但是正则和最长字符串会优先匹配 config B } location ~ image { # 匹配任何以 /iamge/ 开头的地址,匹配符合以后,还要继续往下搜索 # 只有后面的正则表达式没有匹配到时,这一条才会采用这一条 config C } location /foo { # 字符匹配到 /foo,继续往下 config D }
=
means an exact matchrewrite rewrite
Instructions used in rewriting
if (condition ) {} Set conditions and then rewrite
set #Set variables
return #Return status code
break #Jump out rewrite
rewrite #Rewrite
If Syntax format
If space ( Conditions) {
Rewriting mode
}
How to write conditions?
Answer: 3 ways of writing
1: "=" to judge equality, used for string comparison
2: "~" Use regular expressions to match (the regular expressions here are case-sensitive)
~* Case-insensitive regular expressions
3: -f -d -e to determine whether it is a file, a directory, and whether it exists.
The above introduces the detailed explanation of Nginx location syntax configuration, including location and nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.