2

I have an nginx reverse proxy in front of a node.js backend server. In my node app, I am able to stream responses as they become ready, so that the client can start downloading resources referenced in the <head> section of the HTML before the entire response is received.

But, when I put nginx in between, the whole response is buffered before being sent to the client. From this answer, I understand that I can disable this by setting proxy_buffering off; in my nginx config. However, the nginx docs explain that without proxy buffering, a slow client makes the node backend wait (which is why nginx buffers by default).

What I want is the best of both worlds. I want nginx to receive a response and immediately start streaming it to the client. If the client is slower than the backend, nginx buffers the response from the backend and feeds it to the client while the backend is free to process other requests. Oh, and I also want nginx to gzip the streamed response for me on the fly.

Is the configuration possible? It seems like with all of the performance advice on early flushing, I can't be the first person to want this kind of setup. I scanned the nginx docs on the proxy module, but I couldn't find a setting to accomplish this.

Also, on the gzip side of things, it seems like the way to combine streaming with gzip is to do chunked transfer encoding which nginx supports. But, apparently HTTP/2 no longer supports this. What's the new solution then? Or, does it "just work" when you tell nginx to apply gzip to a stream.

Dominic P
  • 417
  • 1
  • 4
  • 18
  • I'm not sure what your app is doing, but it sounds like you probably should be using a websocket instead. Your client side code isn't going to process the response at all until the entire response arrives anyway, so what's the point of trying to stream it? – Michael Hampton May 15 '19 at 03:06
  • Thanks for the reply. This is mostly about the first page load. I actually do leverage Web Sockets after the app is setup. See [here](https://www.stevesouders.com/blog/2009/05/18/flushing-the-document-early/) and [here](https://tech.wayfair.com/2016/12/upgrading-our-stack-for-web-performance-early-flushing-http2-and-more/) and [here](https://developers.google.com/speed/pagespeed/service/FlushResourcesEarly). – Dominic P May 15 '19 at 17:20
  • I have exactly the same issue with the [voila](https://github.com/voila-dashboards/voila/issues/76) python dashboarding framework. It has a "loading" spinner that is displayed when running an app using the built-in server, but does not display when reverse proxying the app behind nginx (unless one turns `proxy_buffering off;`). – leopold.talirz Oct 22 '20 at 22:29

0 Answers0