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 codengx.location.capture
- executes sync Nginx subrequest to the specified URI/page?test=1
- sample URL with arguments to make subrequest tolocal res
- this table will have 4 fields:status
,header
,body
andtruncated
ngx.say
- output given text to clientres.body
- response body returned after subrequest execution
local res = ngx.location.capture('/ip')
ngx.say(res.body)
3.123.32.182
link_youtube: https://youtu.be/IWoYFTKzhvs