下载安装
#wget https://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
#tar xf ngx_openresty-1.7.10.1.tar.gz
#cd ngx_openresty-1.7.10.1
#./configure --with-luajit
#make && make install
【location】
(1)=/ 和 /
location = / {
[configure A]
}
location / {
[configure B]
}
#curl http://localhost/ 匹配B
分析:本来精确匹配应该为A,但当访问http://localhost/时,默认访问网址为http://localhost/index.html,所以匹配为B
(2)=/index.html 和 /
location = /index.html {
[configure A]
}
location / {
[configure B]
}
#curl http://localhost/ 匹配A
(3)/xixi/ 与 ^~ /xixi/
location /xixi/ {
[configure A]
}
location ^~ /xixi/ {
[configure B]
}
报错:
nginx: [emerg] duplicate location "/xixi/" in /usr/local/openresty/nginx/conf/nginx.conf:58
分析:/xixi/与^~ /xixi/都属于普通字符匹配,属于重复配置
(4)~ /xixi/ 与 ^~ /xixi/
location ~ /xixi/ {
[configure A]
}
location ^~ /xixi/ {
[configure B]
}
#curl http://localhost/xixi/ 匹配B
分析:^~ /xixi/优先级大于正则 ~ /xixi/
#curl http://localhost/xixi
报错:404 Not Found
分析:错误日志显示xixi文件不存在
# tail -n5 logs/error.log
2017/02/17 23:19:52 [error] 9732#0: *118 open() "/usr/local/openresty/nginx/html/haha/xixi" failed (2: No such file or directory), client: 127.0.0.1, server: 192.168.204.131, request: "GET /xixi HTTP/1.1", host: "localhost"
(5)~ /xixi/ 与 /xixi/
location /xixi/ {
[configure A]
}
location ~ /xixi/ {
[configure B]
}
#curl http://localhost/xixi/ 匹配B
分析: ~/xixi/ 优先 /xixi/
(6)分析错误日志
2017/02/18 00:05:38 [error] 9987#0: *207 open() "/usr/local/openresty/nginx/html/haha/favicon.ico" failed (2: No such file or directory), client: 192.168.204.1, server: 192.168.204.131, request: "GET /favicon.ico HTTP/1.1", host: "192.168.204.131"