您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
nginx-Location详解之精准匹配
发布时间:2017-11-23 12:16:13编辑:雪饮阅读()
location 语法
location 有”定位”的意思, 根据Uri来进行不同的定位.
在虚拟主机的配置中,是必不可少的,location可以把网站的不同部分,定位到不同的处理方式上.
比如, 碰到.php, 如何调用PHP解释器? --这时就需要location
location 的语法
location [=|~|~*|^~] patt {
}
中括号可以不写任何参数,此时称为一般匹配
也可以写参数
因此,大类型可以分为3种
location = patt {} [精准匹配]
location patt{} [一般匹配]
location ~ patt{} [正则匹配]
一个精准匹配实例分析:
server {
listen 80;
server_name localhost;
location =/index.htm {
root z.com;
index index.htm index.htm;
}
location /index.htm {
root z.com2;
index index.htm index.html;
}
}
第一个location中没有index.htm
第二个location中有index.htm
访问地址如
http://192.168.101.108/index.htm
访问结果是404
分析:由于第一个是精准匹配,第二个是普通匹配,所以先匹配第一个,而第一个没有index.htm所以才会返回404
关键字词:nginx,location