nginxnginx-reverse-proxyngx-brotli

How to prevent nginx reverse proxy recompress the upstream compressed response?


I have nginx reverse proxy that receives brotli compressed response from upstream (Varnish cache). But, the reverse proxy serves brotli compressed response to browser only if I setup "brotli on;" within the reverse proxy server block.

My goal is to have the nginx reverse proxy not handle compression at all. To achieve this, I have following questions:

  1. Is the reverse proxy block expected to un-compress the received response and handle it on it's own? Can't it directly pass the upstream response back to client?

  2. Is there a way to dump proxy response or it's size to nginx logs? This shall help debug the issue better.


Solution

  • I have resolved this so posting this for anyone who may encounter similar issue:

    1. Varnish changed my 'Accept-Encoding' request header to 'gzip'. According to Varnish documentation, this is as designed (see here).
    2. However, the upstream nginx server (behind varnish) responded with non-compressed content because the default for gzip_http_version is 1.0 while the default for proxy_http_version is 1.1. (see here)

    Resolution was achieved by:

    a. setting Varnish to not worry about compression by passing -p http_gzip_support=off to varnishd.

    b. setting gzip_http_version to 1.1 on the upstream Nginx server.

    Deciphering the above behavior became possible because I logged the following on my upstream nginx server (the one behind varnish):

    log_format bytes_sent '$bytes_sent' - '$http_accept_encoding' - '$request';