nginxbrotlingx-brotli

nginx configured with brotli is not compressing large JSON responses


We have a web app server with nginx running in an apline container on Google Cloud.

nginx is built from source, since the spnego plugin we need is only available as source.

The server runs django, and 95% of the responses are JSON data (some can be a few megabytes). Very few static assets except the javascript bundle and a few small icons

I have the following in the nginx config

gzip off;
brotli on;
brotli_comp_level 4;
brotli_static on;
brotli_window 16m;
brotli_types *;

When I check with the browser, I see only the smallest requests being served with brotli - everything over 300 bytes is in gzip encoding.

What am I missing?

Thanks in advance


Solution

  • If your Django app is using the GZipMiddleware or if it is already returning a gzip response, the Nginx Brotli module will not try to compress the response.

    When Nginx receives the response from your App, if the response is already compressed it will not try to compress it again.