ngx_http_gunzip_module

Decompress gzipped responses for clients without gzip support

compiled inBSD-2-Clausesource docs

Overview

ngx_http_gunzip_module is a filter that decompresses responses carrying "Content-Encoding: gzip" for clients that do not support the gzip encoding method. It is useful when data is stored compressed to save space and reduce I/O costs but must still be readable by every client.

When enabled, gzip_http_version, gzip_proxied and gzip_disable from ngx_http_gzip_module are also consulted to decide whether a client supports gzip, and gzip_vary applies as well. It pairs naturally with gzip_static always, which serves .gz files unconditionally and leaves gunzip to handle the clients that cannot read them. This site also ships Brotli and Zstandard modules (/modules/brotli/ and /modules/zstd/) that serve pre-compressed .br and .zst files in the same way.

It is an official nginx module. Upstream does not build it by default and enables it with the --with-http_gunzip_module configure parameter. A typical use is a storage tree that holds only gzipped objects behind a proxy or cache.

Key directives

gunzipEnables or disables decompression of gzipped responses for clients that lack gzip support; default off.
gunzip_buffersNumber and size of buffers used to decompress a response; default 32 4k or 16 8k, one memory page each.
gzip_* awarenessgzip_http_version, gzip_proxied and gzip_disable are also taken into account when judging client support.
gzip_varyWorks with gzip_vary so caches see a Vary: Accept-Encoding header on responses that may be decompressed.
gzip_static alwaysServe only .gz files from disk with gzip_static always and let gunzip decompress for clients that need it.

Example

nginx.conf
location /storage/ { root /srv; # only .gz files exist on disk gzip_static always; gzip_vary on; # decompress for clients that cannot take gzip gunzip on; gunzip_buffers 32 4k; }

Availability

Compiled into every n.wtf nginx binary. Install nginx-extras and the directives above work out of the box, no load_module line needed.