Nginx – Log response body in nginx

load balancingloggingnginxreverse-proxy

How do you log the response body (not request body) in nginx? I could not find such a variable in any of the modules (only the request body).

We are using nginx as a reverse proxy/loadbalancer and would like to parse our API requests & responses from nginx logs.

Thank you!

Best Answer

You could log the headers using $upstream_http_HEADER. Doesn't seem like there is a variable for the response body though but I'm not surprised - this part would be optimized.