proxy_buffering=off, potential problems? other solutions?

Igor Sysoev is at
Fri Feb 29 00:00:17 MSK 2008

On Wed, Feb 27, 2008 at 08:36:27AM +0100, G?bor Farkas wrote:

> >>i have a fairly usual configuration of an nginx webserver + an 
> >>apache-based application-server behind it.
> >>
> >>when requests come in, then nginx proxies it to apache, etc.
> >>
> >>my problem is, that in certain cases, i need that when apache sends the 
> >>response to nginx, nginx should immediately send it to the client.
> >>
> >>i can solve this by simply turning proxy_buffering off, with 
> >>"proxy_buffering = off"
> >
> >If response will be bigger than proxy_buffer_size, then backend will
> >be tied to nginx until the data will be sent to cliant.
> >The maximum data size that nginx can read from backend at once in this mode
> >is proxy_buffer_size.
> >
> maybe i'm misunderstanding something here.
> as far as i see, there are 2 separate "features":
> 1. nginx reads the whole response from the proxied apache and "frees" 
> apache, even when nginx is not immediately able to send it to the client.


> 2. nginx does not start to send the response to the client until the 
> whole response is read from apache (or until it has read 
> "proxy_buffer_size" bytes from apache)


> my problem is #2, not #1.  it seems that doing a "proxy_buffering = off" 
> solves #2, but maybe it does also #1.
> is there a way to only do #2, but not #1?


> maybe it helps if i explain my situation in more detail:
> the apache web-app generates a webpage dynamically, the following way:
> A. generate the first part
> B. do some computation
> C. generate the second part
> it's very important that after step #A, the client immediately gets that 
> part of the webpage. with proxy_buffering enabled, it does not happen,
> because nginx seems to wait for the whole response (or for enough data 
> to fill it's buffers).
> it seems that "proxy_buffering=off" achieves what i need. but as i 
> understood from your response, it also means that the apache-worker will 
> be blocked until the whole response is sent to the client. is there a 
> way to have what i need, and still have buffering enabled? :)
> (well, there is the possibility to send a lot of empty-space in the html 
>  to fill nginx's buffers, but that's not a nice solution :-)

Yes, you are right: apache-worker will be blocked until the whole
response is sent to the client.

Initally, proxying was buffered only, because accelerator should get
response as quickly as possible and free backend.
Then non-buffered hack was added, basically to support memcached.
Then "proxy_buffering off" was appeared.
I want to rewrite all upstream code including balancers and it will
next major target after caching will be complete.

Igor Sysoev

More information about the nginx mailing list