Nginx Request and Response Buffering
Separate the two directions
Request buffering concerns data traveling from the client toward the application. Response buffering concerns data traveling back. They are separate switches. In a typical site, buffering helps an application finish its response even when the browser is slow, subject to memory and disk capacity.
upload: client -> request buffers -> applicationdownload: client <- response buffers <- applicationBuffering is not caching across requests. It does not necessarily wait for the full response before sending the first bytes.
Choose a response policy
For ordinary HTML or JSON, keep the standard response buffering policy unless measurements justify a change. For an event stream, forwarding chunks promptly is often more important than freeing the upstream quickly.
proxy_pass http://catalog_reuse;proxy_http_version 1.1;proxy_set_header Connection "";proxy_buffering off;The application must flush data; clients and other intermediaries can also buffer. Off is not a guarantee of zero latency. An upstream can signal its preference with X-Accel-Buffering, unless Nginx is configured to ignore that response header. Slow clients can keep upstream sockets busy longer.
Memory and disk trade-offs
The first response buffer needs room for headers. Additional response buffers hold body data; a limit on busy buffers constrains how much is being sent while reading continues. Excess data may spill to temporary storage. The following explicit sizes are illustrative, not production defaults.
proxy_buffer_size 8k;proxy_buffers 8 8k;proxy_busy_buffers_size 16k;proxy_max_temp_file_size 0;The configured initial plus body buffer capacity is nominally 72 KiB per buffered response (8 + 8×8); actual allocated memory and other overhead vary. The busy limit is not an extra 16 KiB. Zero ordinary spill size can increase backpressure; it does not disable disk-based proxy caching or request-body files. Plan private temporary directories and observe disk, concurrency and latency. proxy_temp_file_write_size controls the response spill write batch.
Uploads and replayability
With request buffering on, Nginx reads the client body before sending it upstream. Turning it off can let a large upload begin processing sooner, but a slow sender now holds upstream resources and the body may not be replayable once forwarded. For chunked client requests, the upstream protocol also matters.
client_max_body_size 64k;proxy_pass http://catalog_reuse;proxy_http_version 1.1;proxy_set_header Connection "";proxy_request_buffering off;proxy_next_upstream off;This bounds the synthetic lab input; choose real upload limits based on the product. Chunked bodies are still buffered when proxying without HTTP/1.1 or HTTP/2 support as documented. A body-size limit is not a timeout or disk quota. The staged lab verifies equal payloads in both modes; timing and temporary-file behavior require separate runtime observation.
Practice
Choose request and response policies for small JSON, a live event stream, and a bounded streaming upload. Explain one resource trade-off for each.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Nginx Request and Response Buffering
Choose buffering policies for normal responses, streaming and uploads.
Which setting affects the client upload body?
Does response buffering on require the whole response before any downstream bytes?
Which directive limits ordinary response spill files?
Why might a stream arrive late with buffering off?
What risk arises after an unbuffered upload has begun reaching the backend?