# ============================================================================= # Payload log: one JSON line per request, body included, for inspecting what # actually arrives at the edge. Included at http level by BOTH nginx.conf and # nginx_dev.conf, so it is plain nginx (no envsubst) like security_headers.conf. # # WHERE IT GOES # /var/log/nginx/payloads/ is bind-mounted from ./logs/nginx on the host. # The `traffic` container tails the file to its stdout so Dozzle (/dozzle/) # shows it as its own clean stream of JSON. The `compact` access log is # untouched and still goes to the container's stdout. # # WHAT IS NOT CAPTURED # - Bodies larger than client_body_buffer_size: nginx spools those to a # temp file and leaves $request_body empty. Uploads therefore log with an # empty body (their size is still in `len`). # - Bodies of requests nginx answers itself (redirects, static files): it # never reads them, so $request_body is empty there too. # - Responses. nginx cannot log a proxied response body. # - auth_request subrequests: log_subrequest is off by default. # ============================================================================= # 64k keeps ordinary JSON/GraphQL bodies in memory (the default is 16k on # 64-bit), which is the only case where $request_body is filled. It is a # per-request buffer only allocated when a body arrives, so the cost is small. client_body_buffer_size 64k; # Redaction: any body mentioning a password, token or secret is logged as a # placeholder rather than having the field stripped, because nginx has no JSON # parser. That catches /auth/login, the GraphQL login and change-password # mutations and the refresh-token call in one rule. Over-matching (a query that # merely selects a field named *token*) costs a hidden body, never a leak. # map is evaluated lazily at log time, after the body has been read. map $request_body $logged_body { "~*(password|token|secret)" "[redacted]"; default $request_body; } # escape=json makes each line valid JSON (quotes, newlines and control bytes # in the body are escaped), so Dozzle renders it as fields and `jq` reads it. log_format payloads escape=json '{' '"time":"$time_iso8601",' '"ip":"$remote_addr",' '"method":"$request_method",' '"host":"$host",' '"uri":"$request_uri",' '"status":"$status",' '"rt":"$request_time",' '"ctype":"$content_type",' '"len":"$content_length",' '"referer":"$http_referer",' '"ua":"$http_user_agent",' '"body":"$logged_body"' '}'; access_log /var/log/nginx/payloads/payloads.log payloads;