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

当我使用openresty通过Lua监控IP时,为什么访问根目录时会调用两遍access_by_lua_file 以下是我使用的示例:

http {
   access_by_lua_file lua/test.lua;
   server{
    location / {
    default_type text/html;
    }
   }
}
点赞
用户9783845
用户9783845

需要注意的是,使用索引文件会导致内部重定向,也就是说,对根目录(/)的请求会被内部重定向到 /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"

2020-08-17 12:21:53