Nginx location syntax configuration detailed explanation location meaning $location location reset

WBOY
Release: 2016-07-29 08:49:25
Original
1947 people have browsed it

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 types

location = 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 of
 location = / {
	 # 精确匹配 / ,主机名后面不能带任何字符串
          config A
       }
 location / {
 	 # 因为所有的地址都以 / 开头,所以这条规则将匹配到所有请求
 	 # 但是正则和最长字符串会优先匹配
         config B
  }
location ~ image {
        # 匹配任何以 /iamge/ 开头的地址,匹配符合以后,还要继续往下搜索
        # 只有后面的正则表达式没有匹配到时,这一条才会采用这一条
        config C
}
location /foo {
        # 字符匹配到 /foo,继续往下
        config D
}
Copy after login

    • = means an exact match
      For example, in A, only the request at the end of the root directory is matched, and no strings can follow.
    • ~ starts with a case-sensitive regular match;
    • ~* starts with a case-insensitive regular match
    • / universal match, if there is no other match, any request will match
      • / -> config A
        Exact exact match
      • /image/logo.png -> config C
        After matching B, there is no match below, use C
      • /foo -> config D
        match to F, below match to D, stop going down
      • /abc/def -> config B
        matching rule B
      nginx location配置,nginx location 过滤,nginx geo location,randomlocation,locationmanager,locationclient,setlocation,configlocation,echolocation,cursorlocation,locationholic,bdlocation,location的意思,$location,location重定

rewrite 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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template