


Nginx location syntax configuration detailed explanation location meaning $location location reset
Jul 29, 2016 am 08:49 AMlocation 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 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
- / -> config A
-
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.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to allow external network access to tomcat server

What are the nginx start and stop commands?

What are the differences between tomcat and nginx

How to deploy nodejs project to server

How to solve the problem of nginx when accessing the website
