I need to log request/response size(body+headers) in the access_log. Any idea how to do it in nginx? In apache we can do it using %I..%O...

3 Answers 3


I would use these 2 parameters in nginx.conf:

log_format perf '$remote_addr $status - $request_length $bytes_sent'

According to documentation ( http://wiki.nginx.org/HttpLogModule) the $request_length is only the body of the request, but I have confirmed that it includes all headers (I have some GET requests with lots of cookies which have more than 1400 bytes in total). $bytes_sent is total number of bytes sent to the client (as opposed to $body_bytes_sent which is compatible with apache %B).

  • $body_sent is not a variable in nginx logging module Mar 13, 2023 at 5:12
  • 1
    @user1559834 seems it is $body_bytes_sent now. Not sure if they changed it since my post in year 2012 or it was a typo.
    – Marki555
    Mar 14, 2023 at 10:23

Taken from ngx_http_log_module:

$bytes_sent: the number of bytes sent to a client

$connection: connection serial number

$connection_requests: the current number of requests made through a connection (1.1.18)

$msec: time in seconds with a milliseconds resolution at the time of the log write

$pipe: “p” if request was pipelined, “.” otherwise

$request_length: request length (including request line, header, and request body)

$request_time: request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client

$status: response status

$time_iso8601: local time in the ISO 8601 standard format

$time_local: local time in the Common Log Format


request length (including request line, header, and request body)

response length (including header, and body)

response length only include body.

  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 11, 2021 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .