zstd-nginx-module

Zstandard response compression with dictionary support

compiled inBSD-2-Clausesource

Overview

zstd-nginx-module adds Zstandard (zstd) compression to nginx. Zstandard is a compression algorithm developed at Facebook that targets high compression ratios at fast compression and decompression speeds.

Like ngx_brotli, it ships a filter module for on-the-fly compression and a static module that serves pre-compressed .zst files. It can also load an external dictionary trained on your content, which improves ratios on small responses.

The module is written and maintained by Alex Zhang (tokers). Upstream labels it experimental, and it is enabled per location, so it is easy to roll out gradually.

Key directives

zstdEnables on-the-fly zstd compression of responses; off by default.
zstd_comp_levelSets the compression level, default 1.
zstd_typesLimits compression to the listed MIME types, default text/html.
zstd_min_lengthSkips responses shorter than the given byte length, default 20.
zstd_staticServes a pre-compressed .zst file next to the original when the client accepts zstd.
zstd_dict_fileLoads an external zstd dictionary used for both dynamic compression and decompression.

Example

nginx.conf
zstd on; zstd_comp_level 3; zstd_min_length 256; zstd_types text/plain text/css application/javascript application/json image/svg+xml; # serve pre-compressed .zst files when they exist on disk zstd_static on;

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.