9951 explained code solutions for 126 technologies


nginx-luaHow to log request headers


log_format log_hdrs '[$time_local] "$request" "$req_hdr"';

server {
  location / {
    set_by_lua_block $req_hdr {
      return ngx.req.get_headers()['Accept']
    }
    
    access_log /var/log/nginx/lua.log log_hdrs;
  }
}ctrl + c
log_format

specify custom log format to log request body

log_hdrs

access log format name with request header

$req_hdr

this variable will contain specific request header value

set_by_lua_block

nginx-lua module directive that sets specified variable with a result from Lua code

ngx.req.get_headers()

returns table with request headers

Accept

sample HTTP header to log value of

access_log

set access log path and format

/var/log/nginx/lua.log

path to access log