openresty为什么在访问根目录时access_by_lua\ufile会调用两次



当我使用openresty通过Lua监视器监视IP时,为什么在访问根目录时access_by_Lua\ufile会调用两次以下是我的使用方法:

http {
access_by_lua_file lua/test.lua;
server{
location / {
default_type text/html;
}
}
}

https://nginx.org/en/docs/http/ngx_http_index_module.html

应该注意的是,使用索引文件会导致内部重定向

也就是说,对根(/(的请求在内部重定向到/index.html

这里有一个演示:

http {
access_log /dev/stdout;
access_by_lua_block {
ngx.log(ngx.INFO, ngx.var.uri, ' ', ngx.req.is_internal())
}
server {
listen 8888;
location / {
default_type text/html;
}
}
}

curl localhost:8888/index.html:

2020/08/17 15:14:22[info]2411#22411:*5[lua]access_by_lua(nginx.conf:15(:2:/index.html false,客户端:127.0.0.1,服务器:,请求:"GET/index.html HTTP/1.1";,主机:";localhost:8888";

127.0.0.1-[2020年8月17日5:14:22+0300]";GET/index.html HTTP/1.1";200 14〃-"quot;卷曲/7.68.0";

curl localhost:8888/:

2020/08/17 15:15:31[info]2411#22411:*6[lua]access_by_lua(nginx.conf:15(:2:/false,客户端:127.0.0.1,服务器:,请求:"GET/HTTP/1.1";,主机:";localhost:8888";

2020/08/17 15:15:31[info]2411#22411:*6[lua]access_by_lua(nginx.conf:15(:2:/index.html true,客户端:127.0.0.1,服务器:,请求:"GET/HTTP/1.1";,主机:";localhost:8888";

127.0.0.1-[2020年8月17日:15:31+0300]";GET/HTTP/1.1";200 14〃-"quot;卷曲/7.68.0";

最新更新