-- nginx.conf

worker_processes 2;
user root;
pcre_jit on;

events {
worker_connections 1024;
}

http {
lua_package_path '$prefix/?.lua;$prefix/resty_modules/lualib/?.lua;;';
lua_code_cache off;
default_type text/plain;
keepalive_timeout 65;

server {
    listen 8080;
    location / {
        content_by_lua_file lua/not_found.lua;
    }

    location = /test {
        #  rewrite_by_lua_file lua/check.lua;
        content_by_lua_file lua/test.lua;
    }

    location = /other {
        content_by_lua_file lua/other.lua;
    }

}

}

-- test.lua

local res = ngx.location.capture("/other")
ngx.say(res.body)
local m, err = ngx.re.match("hello, mei", "HELLO, (.{2})", "i")
ngx.say(m[0])
ngx.say(m[1])

-- other.lua

local res = ngx.location.capture("/other")
ngx.say(res.body)
local m, err = ngx.re.match("hello, mei", "HELLO, (.{2})", "i")
ngx.say(m[0])
ngx.say(m[1])

===================================
如果lua_code_cache on; 则没有任何问题
当lua_code_cache off;
curl http://localhost:8080/other
curl http://localhost:8080/test 后会出现子请求循环

这是什么原因呢?

    一般的匹配也会
    local res = ngx.location.capture("/other")
    ngx.say(res.body)
    local m, err = ngx.re.match("hello, mei", "hello")
    ngx.say(m[0])

      2022/04/18 08:54:43 [error] 18705#18705: *207 lua subrequests cycle while processing "/other", client: 127.0.0.1, server: , request: "GET /test HTTP/1.1", subrequest: "/other", host: "localhost:8080"
      2022/04/18 08:54:43 [error] 18705#18705: *207 lua entry thread aborted: runtime error: /root/study/test/lua/test.lua:1: failed to issue subrequest: -1

        跟具体代码没有什么关系。
        只要是lua_code_cache off;
        先curl 子请求的api
        然后curl 主请求都会这样。并且主请求调用子请求后的输出没了

          Write a Reply...