$bytes_sent
The $bytes_sent variable contains the total number of bytes sent to the client in response to a request. — NGINX Core (HTTP)
Description
The $bytes_sent variable in NGINX tracks the total number of bytes transmitted to the client during response. This variable is computed during the request processing phase and is available in all contexts where logging occurs. It reflects not only the raw response body but also any additional bytes sent, such as HTTP headers. The value of this variable is established when NGINX begins delivering the response to the client and continues to accumulate throughout the transmission process until the response is fully sent. Typically, $bytes_sent can vary significantly based on the type of content being delivered; for instance, static files will report the exact file size in bytes, while dynamic content generated by scripts can be less predictable. Additionally, and can affect the size reported due to differences in content length, headers, and compression. Overall, developers and system administrators utilize this variable primarily for analyzing bandwidth usage, calculating transfer statistics, and tuning server performance for efficient client response handling.
Config Example
log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $bytes_sent'; access_log /var/log/nginx/access.log main;
Subsystem
httpCacheable
YesContexts
http, server, location, if, logThe value of $bytes_sent is cumulative and only provides the total bytes sent for the specific request being processed at that moment.
In cases of small responses, or when responses are cached, the value may not reflect expected bandwidth metrics.
For chunked transfer encoding responses, $bytes_sent may not equate to a precise content size measurement during response delivery.