9951 explained code solutions for 126 technologies


nginx-luaHow to use subrequests


server {
  location / {
    content_by_lua_block {
      local res = ngx.location.capture('/page?test=1')
      ngx.say(res.body)
    }
  }
}ctrl + c
content_by_lua_block

nginx-lua module directive to specify block of Lua code

ngx.location.capture

executes sync Nginx subrequest to the specified URI

/page?test=1

sample URL with arguments to make subrequest to

local res

this table will have 4 fields: status, header, body and truncated

ngx.say

output given text to client

res.body

response body returned after subrequest execution