Skip to content

Instantly share code, notes, and snippets.

@lcrilly
lcrilly / README.md
Last active July 19, 2024 15:50
Logging request headers with njs

Logging request headers with njs

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.

nginx.conf

js_include functions.js;
js_set $headers_json headers_to_json;

log_format json escape=none '{"timestamp":"$time_iso8601",'