Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 912 Bytes

how-to-use-subrequests.md

File metadata and controls

32 lines (26 loc) · 912 Bytes

How to use subrequests

server {
  location / {
    content_by_lua_block {
      local res = ngx.location.capture('/page?test=1')
      ngx.say(res.body)
    }
  }
}
  • content_by_lua_block - lib: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

Example:

local res = ngx.location.capture('/ip')
ngx.say(res.body)
3.123.32.182


link_youtube: https://youtu.be/IWoYFTKzhvs