技术解析
按照 nginx 文档 中对 index
指令的说法:
It should be noted that using an index file causes an internal redirect, and the request can be processed in a different location. 美国服务器For example, with the following configuration:
location = / {
index index.html;
}
location / {
...
}
a “/” request will actually be processed in the second location as “/index.html ”.
在匹配了一个 location
块后,如果这个块有或者继承了 index
指令,就会触发一次内部重定向,也就是重新开始一次 location search, 然后匹配到了第二个 location block.
但是在我的配置中:
server {
listen 80;
server_name ubuntu;
location = / {
index index.html;
return 200 '/exact';
}
location / {
return 200 '/';
}
}
使用 curl 请求得到的结果都是 /exact
:
# curl http://ubuntu
/exact
# curl http://ubuntu/
/exact
也就是说,实际匹配的确实第一个 location block, 请问这是为什么呢?