openresty为什么访问根目录时access_by_lua_file会调用两次

openresty why does access_by_lua_file call twice when accessing the root directory

我用openresty通过Lua监听IP时,为什么access_by_lua_file在访问根目录时会调用两次 以下是我的使用方法:

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

It should be noted that using an index file causes an internal redirect

也就是说,对根(/)的请求被内部重定向到/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] 22411#22411: *5 [lua] access_by_lua(nginx.conf:15):2: /index.html false, client: 127.0.0.1, server: , request: "GET /index.html HTTP/1.1", host: "localhost:8888"

127.0.0.1 - - [17/Aug/2020:15:14:22 +0300] "GET /index.html HTTP/1.1" 200 14 "-" "curl/7.68.0"

curl localhost:8888/:

2020/08/17 15:15:31 [info] 22411#22411: *6 [lua] access_by_lua(nginx.conf:15):2: / false, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8888"

2020/08/17 15:15:31 [info] 22411#22411: *6 [lua] access_by_lua(nginx.conf:15):2: /index.html true, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8888"

127.0.0.1 - - [17/Aug/2020:15:15:31 +0300] "GET / HTTP/1.1" 200 14 "-" "curl/7.68.0"