This configuration can be used to log all of the request headers presented by a client. We use the JavaScript (njs) module to iterate over each header, returning a list of JSON key-value pairs which are then included in a JSON log format.
js_include functions.js;
js_set $headers_json headers_to_json;
log_format json escape=none '{"timestamp":"$time_iso8601",'