- 什么是location
location是Nginx配置文件中用来配置控制访问网站的路径的配置, 但一个server可以有多个location配置,
多个location的优先级可以按下图区分。
- location匹配符号
匹配符 | 匹配规则 | 优先级 |
---|---|---|
= | 精确匹配 | 1 |
^~ | 以某个字符串开头 | 2 |
~ | 区分大小写的正则匹配 | 3 |
~* | 不区分大小写的正则匹配 | 3 |
/ | 通用匹配,任何请求都会匹配到 | 4 |
- 案例
server {
listen 80;
server_name _;
location ~* /python {
default_type text/html;
return 200 "Location ~*";
}
location ~ /Python {
default_type text/html;
return 200 "Location ~";
}
location ^~ /python {
default_type text/html;
return 200 "Location ^~";
}
location = /python {
default_type text/html;
return 200 "Location =";
}
}