index index.html index.htm index.php l.php;
if (!-e $request_filename) {
rewrite /[ac]\d+\.html /index/index/home last;
rewrite ^/admin$ /admin/login/login last;
rewrite ^(.*)$ /index.php?s=$1 last;
break; } autoindex off;
}
1. Break will stop subsequent rewriting rules after rewriting the statement: rewrite ^(.*)$ /index.php?s=$1 break; Including other locations, no matching will be performed.
2. Write alone : rewrite ^(.*)$ /index.php?s=$1 last;
break;
will only stop the rewrite rules for this location. Other locations will be executed with the rewritten url
3.last will re-match all rewrite rules with the rewritten url. Including in this location means rematching in the entire server.
4. Note: It is very important to note that the rewrite rule will first match the outer layer of location, such as location =/1.php{rewrite ^(.*)$ /2.php last; , location ~ \.php(.* )$ , location /flag { rewrite ^(.*)$ /1.php last; . Three rules. Accessing http://localhost/flag/1.php will not access 2.php
Instead, it appears: No input file specified. Because the location ~ \.php(.*)$ rule has been matched. The file cannot be found because there is no /flag/1.php.
So if you want to access /flag/1.php to get the content of 2.php: modify location /flag { rewrite ^(.*)$ /1.php last to location ^~ /flag { rewrite ^(.*)$ / 1. php last
5. The url matching priority of nginx location:
1, = First, the exact match has the highest priority
2, ^~ followed by a match starting with a specific regular string, this is not a regular
3. ~ , ~*, !~, !~* are regular matching in order, followed by case-sensitive regular matching, case-insensitive regular matching, case-sensitive regular matching, indistinguishable Regular mismatch of upper and lower case,
4. The last is the universal character matching of /
The above is the url matching priority of the nginx location
Location priority example
The configuration items are as follows:
location = / {
# 仅仅匹配请求 /
[ configuration A ]
}
location / {
# 匹配所有以 / 开头的请求。
# 但是如果有更长的同类型的表达式,则选择更长的表达式。
# 如果有正则表达式可以匹配,则优先匹配正则表达式。
[ configuration B ]
}
location /documents/ {
# 匹配所有以 /documents/ 开头的请求。
# 但是如果有更长的同类型的表达式,则选择更长的表达式。
# 如果有正则表达式可以匹配,则优先匹配正则表达式。
[ configuration C ]
}
location ^~ /images/ {
# 匹配所有以 /images/ 开头的表达式,如果匹配成功,则停止匹配查找。
# 所以,即便有符合的正则表达式location,也不会被使用
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
# 匹配所有以 gif jpg jpeg结尾的请求。
# 但是 以 /images/开头的请求,将使用 Configuration D
[ configuration E ]
}
Request matching example
/ -> configuration A
/index.html -> configuration B
/documents/document.html -> configuration C
/images/1.gif -> configuration D
/documents/1.jpg -> configuration E
Note that the above matches have nothing to do with the order defined in the configuration file.