I need to set up a HTTP reverse proxy that will be able to cache requests to the upstream server.

The upstream server serves only static files.

The issue I am facing is that I need a proxy that is capable of starting first byte ASAP (it can't wait for the whole request to buffer) while still caching. It is because my files can be quite large (a few hundred megabytes) but app requirement is to have fast response times.

I tried to use nginx but when I disable proxy_buffering it stops caching at all.

Is there any widely-available, well tested open source project that can do this? Varnish? Squid? HAProxy?

  • Have you considered trying out a Content delivery network of your choice?
    – M. Glatki
    Jan 23, 2017 at 18:49
  • It's not an option for me, business requirement is that I must be able to put my system on client's private infrastructure.
    – mspanc
    Jan 23, 2017 at 18:58
  • I don't have a good answer for you, but you probably want to look for something that can rewrite the request and make use of multiple simultanious byte range requests, assuming upstream supports ranges (because that is what you are describing). Off the top of my head however, I can only think of really hacky ways to accomplish this using helper scripts in squid.
    – Aaron
    Jan 23, 2017 at 22:57

2 Answers 2


Varnish will be good for the job:

sub vcl_backend_response {

    # ... 

    # Large static files are delivered directly to the end-user without
    # waiting for Varnish to fully read the file first.
    # Varnish 4 fully supports Streaming, so use streaming here to avoid locking.
    if (bereq.url ~ "^[^?]*\.(mp[34]|rar|rpm|tar|tgz|gz|wav|zip|bz2|xz|7z|avi|mov|ogm|mpe?g|mk[av]|webm)(\?.*)?$") {
        unset beresp.http.set-cookie;
        set beresp.do_stream = true;  
        set beresp.do_gzip = false;   # Don't try to compress it for storage

    # ...


You can setup two nginx servers, one with enabled proxy_buffering, and the next one that will cache responses from upstream.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.