Home Backend Development PHP Tutorial Nginx location syntax configuration detailed explanation location meaning $location location reset

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

Jul 29, 2016 am 08:49 AM
location nginx

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.

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

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to allow external network access to tomcat server How to allow external network access to tomcat server Apr 21, 2024 am 07:22 AM

How to allow external network access to tomcat server

What are the nginx start and stop commands? What are the nginx start and stop commands? Apr 02, 2024 pm 08:45 PM

What are the nginx start and stop commands?

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

What are the differences between tomcat and nginx What are the differences between tomcat and nginx Dec 27, 2023 pm 05:07 PM

What are the differences between tomcat and nginx

Welcome to nginx!How to solve it? Welcome to nginx!How to solve it? Apr 17, 2024 am 05:12 AM

Welcome to nginx!How to solve it?

How to register phpmyadmin How to register phpmyadmin Apr 07, 2024 pm 02:45 PM

How to register phpmyadmin

How to deploy nodejs project to server How to deploy nodejs project to server Apr 21, 2024 am 04:40 AM

How to deploy nodejs project to server

How to solve the problem of nginx when accessing the website How to solve the problem of nginx when accessing the website Apr 02, 2024 pm 08:39 PM

How to solve the problem of nginx when accessing the website

See all articles