9951 explained code solutions for 126 technologies


nginx-luaHow to log request body


lua_need_request_body on;
log_format log_body '[$time_local] "$request" "$request_body"';

server {
  location / {
    content_by_lua 'ngx.say("ok")';
    access_log /var/log/nginx/lua.log log_body;
  }
}ctrl + c
lua_need_request_body

ask Nginx to fill $request_body variable using nginx-lua

log_format

specify custom log format to log request body

$request_body

this variable will contain request body

content_by_lua

nginx-lua module directive to execute specified Lua code

ngx.say("ok")

just outputs ok so the client gets something in return

access_log

set access log path and format

/var/log/nginx/lua.log

path to access log