# Proxy\_buffering

**URL:** <https://www.ruby-forum.com/t/proxy-buffering/217856>\
**Category:** NGINX\
**Created:** [March 14, 2012, 10:19pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856 "2012-03-14T22:19:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 14, 2012, 10:19pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/1 "2012-03-14T22:19:29Z")

</div>

Hey Guys,

I’m new to nginx and have a question about the proxy\_buffering feature.  
Our topology is very easy:  
Just nginx - No apache behind it.  
Our site gets the content (text,pictures,videos) of different sites via  
php and serves it to the client.

My question is:  
Do we need the proxy\_buffering? Could we turn it off without performance  
issues?  
I really don’t understand this feature, maybe someone could explain it  
for me. 🙂

Thanks!

Posted at Nginx Forum:

> **[proxy\_buffering](https://forum.nginx.org/read.php?2,223845,223845#msg-223845)**
>
> Hey Guys, I'm new to nginx and have a question about the proxy\_buffering feature. Our topology is very easy: Just nginx - No apache behind it. Our site gets the content (text,pictures,videos) of different sites via php and serves it to the client.

---

<div class="post-metadata">

**Author:** ![nginxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nginxer](https://www.ruby-forum.com/u/nginxer)\
**Post date:** [March 14, 2012, 10:41pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/2 "2012-03-14T22:41:54Z")

</div>

> I’m new to nginx and have a question about the proxy\_buffering feature.

> Our topology is very easy:  
> Just nginx - No apache behind it.  
> Our site gets the content (text,pictures,videos) of different sites via  
> php and serves it to the client.

> My question is:  
> Do we need the proxy\_buffering? Could we turn it off without performance  
> issues?

You do need it. Otherwise any slow client will block an entire php  
process for a long time.

> I really don’t understand this feature, maybe someone could explain it  
> for me. 🙂

> **[upstream response is buffered to a temporary file](http://mailman.nginx.org/pipermail/nginx/2012-March/032608.html)**

---

<div class="post-metadata">

**Author:** ![nginxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nginxer](https://www.ruby-forum.com/u/nginxer)\
**Post date:** [March 14, 2012, 11:58pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/3 "2012-03-14T23:58:47Z")

</div>

This does not help! :-/

One says that I need it and the other says I don’t.  
Maybe the information I provided are too lean.

We run php-fpm and nginx on the same server.  
The php scripts will get the contents from different sites and sends  
them to the client.  
We do NOT own these “different sites” (= Google, Flickr, Youtube)

@Alexandr G.:  
I still don’t understand what proxy\_buffering really does.  
When a client wants to visit Google, the php script will get the content  
from Google and sends it to the client.

So where is the role of proxy\_buffering?  
Could you provide a scenario how proxy\_buffering will exactly work for  
our topology?

Thanks!

Posted at Nginx Forum:

> **[Re: proxy\_buffering](https://forum.nginx.org/read.php?2,223845,223849#msg-223849)**
>
> Hey Guys, I'm new to nginx and have a question about the proxy\_buffering feature. Our topology is very easy: Just nginx - No apache behind it. Our site gets the content (text,pictures,videos) of different sites via php and serves it to the client.

---

<div class="post-metadata">

**Author:** ![nginxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nginxer](https://www.ruby-forum.com/u/nginxer)\
**Post date:** [March 14, 2012, 11:43pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/4 "2012-03-14T23:43:56Z")

</div>

Enabling proxy\_buffering, disk I/O will increase significantly. If  
you’re  
running nginx and php on the same server, maybe it’s not a good idea to  
enable it.

---

<div class="post-metadata">

**Author:** ![nginxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nginxer](https://www.ruby-forum.com/u/nginxer)\
**Post date:** [March 15, 2012, 1:09am UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/5 "2012-03-15T01:09:24Z")

</div>

On Thu, Mar 15, 2012 at 12:57 AM, nginxer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This does not help! :-/
> 
> One says that I need it and the other says I don’t.  
> Maybe the information I provided are too lean.

It was fine.

Have you read this?

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffering)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

I’m not sure what is so confusing about it. If you can receive an  
entire response from your giant php process you can send another  
request there right away, making it a lot more efficient, so it won’t  
occupy those amounts of memory for nothing. Unless you have a lot of  
memory.

---

<div class="post-metadata">

**Author:** ![nginxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nginxer](https://www.ruby-forum.com/u/nginxer)\
**Post date:** [March 15, 2012, 12:11pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/6 "2012-03-15T12:11:34Z")

</div>

OK.  
The last link from you was helpful!

But one last question to see if I got this right:

Imagine following scenario:

The proxy\_buffers are empty. A client wants to visit let’s say  
[google.com](http://google.com). Our php script gets the content of [google.com](http://google.com), sends it to  
the client and nginx will also buffer the response from [google.com](http://google.com) in a  
proxy\_buffer.

Is that right so far?

So the next time if a client wants to visit [google.com](http://google.com) nginx will take  
the response from a proxy\_buffer without making a request to  
[google.com](http://google.com).

Right?

If I understood it right, proxy\_buffering is caching?

The term “proxied server” confused me…

Thanks Alexandr G.!

Posted at Nginx Forum:

> **[Re: proxy\_buffering](https://forum.nginx.org/read.php?2,223845,223877#msg-223877)**
>
> Hey Guys, I'm new to nginx and have a question about the proxy\_buffering feature. Our topology is very easy: Just nginx - No apache behind it. Our site gets the content (text,pictures,videos) of different sites via php and serves it to the client.

---

<div class="post-metadata">

**Author:** ![nginxer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ce73a5/32.png) [@nginxer](https://www.ruby-forum.com/u/nginxer)\
**Post date:** [March 15, 2012, 11:07pm UTC](https://www.ruby-forum.com/t/proxy-buffering/217856/7 "2012-03-15T23:07:42Z")

</div>

On Thu, Mar 15, 2012 at 07:10:47AM -0400, nginxer wrote:

Hi there,

> But one last question to see if I got this right:

I don’t think you have.

“buffering” and “caching” are two different things. “caching” is not  
involved here at all.

> Imagine following scenario:
> 
> The proxy\_buffers are empty.

A proxy\_buffer is associated with a single proxy\_pass connection. So  
the buffers are empty at the start and end of the connection, and may  
hold something in between.

> A client wants to visit let’s say [google.com](http://google.com). Our php script gets

If you’re using php and php-fpm and not apache, you’re probably not  
using proxy\_pass but fastcgi\_pass. That means the actual directives you  
will want to use will probably start with fastcgi\_ rather than proxy\_,  
but the outline is the same.

> the content of [google.com](http://google.com), sends it to the client

Upstream doesn’t talk to the client.

Upstream talks to nginx, and nginx talks to the client.

> and nginx will also buffer the response from [google.com](http://google.com) in a  
> proxy\_buffer.
> 
> Is that right so far?

Perhaps it is easier to think of the full process as a chain of  
processes.

web browser talks to nginx, over a 1 MB/s link.  
nginx talks to upstream server, over a 100 MB/s link.  
upstream server returns 100 MB of content to nginx.  
nginx returns 100 MB of content to web browser.

With proxy\_buffering on, nginx can hold the whole 100 MB, so the  
nginx-upstream connection can be closed after 1 s, and then nginx can  
spend 100 s sending the content to the web browser.

With proxy\_buffering off, nginx can only take the content from upstream  
at  
the same rate that nginx can send it to the web browser.

The web browser doesn’t care about the difference – it still takes 100  
s for it to get the whole content.

nginx doesn’t care much about the difference – it still takes 100 s to  
feed the content to the browser, but it does have to hold the connection  
to upstream open for an extra 99 s.

Upstream does care about the difference – what could have taken it 1  
s actually takes 100 s; and for the extra 99 s, that upstream server is  
not serving any other requests.

Usually: the nginx-upstream link is faster than the browser-nginx link;  
and upstream is more “heavyweight” than nginx; so it is prudent to let  
upstream finish processing as quickly as possible.

Hence buffering.

> So the next time if a client wants to visit [google.com](http://google.com) nginx will take  
> the response from a proxy\_buffer without making a request to  
> [google.com](http://google.com).
> 
> Right?

No. That would be caching. The directives to configure that tend to have  
the word “cache” in them.

> If I understood it right, proxy\_buffering is caching?
> 
> The term “proxied server” confused me…

When you “proxy\_pass”, what you proxy\_pass to is the proxied server.

If you are using fastcgi\_pass, then the content at

> **[Module ngx\_http\_fastcgi\_module](http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html)**

is probably more interesting to you.

There is no explicit “fastcgi\_buffering” directive; it is effectively  
always “on”.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
