1

with proxy_pass - how does NGINX handle situation when the client is slower connection than the upstream server, say the upstream server is pushing the content to the nginx server at 12MBPS, but the client reading the content is on a 1.2MBPS connection?

    location / {

    proxy_buffering    off;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffer_size  128k;
    proxy_buffers 100  128k;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP   $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://proxy.backend.server;}

In this case, proxy_buffering is turned off, does Nginx save the data to be served when the client reaches that point in the data?

1 Answer 1

1

It can be found from docs for proxy_buffering:

When buffering is disabled, the response is passed to a client synchronously, immediately as it is received. nginx will not try to read the whole response from the proxied server. The maximum size of the data that nginx can receive from the server at a time is set by the proxy_buffer_size directive.

In other words, NGINX keeps the connection to the backend a longer time (as long as the client needs to download the entire response). With buffering disabled, the connection is synchronous between the client and the backend.

Whether you want to keep proxy buffering off is based on resources. Typically there's a resource-hungry backend like PHP-FPM, so it's not advisable to keep it hanging around for the duration of client downloading the response. Thus for PHP-FPM as backend (fastcgi_buffering is the right directive there), I'd keep it on.

Also worth noting that even with proxy buffering disabled, there's still some buffering around like proxy_buffer_size directives. And here's an intro on sizing it properly. It holds headers only. 128k is a size of a (maybe) typical HTML page. HTTP headers are much much smaller than that.

1
  • Thank you, it now makes more sense. Would it also make more sense to raise those values and do some proxy_buffering = on if we're proxying 10MB files? Commented Sep 11, 2021 at 13:34

You must log in to answer this question.

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