2808 explained code solutions for 75 technologies


nginx-luaHow to modify response header with Lua


server {
  location / {
    content_by_lua_block {
      ngx.header["Content-type"] = 'application/json'
      ngx.say("[1,2,3]")
    }
  }
}ctrl + c
content_by_lua_block

nginx-lua module directive to specify block of Lua code

ngx.header

allows to set response headers

Content-type

response header to modify

application/json

new header value to set

ngx.say

output given text to client

[1,2,3]

sample text in JSON format to output (online example)