http-zstd #

Compresses responses with Zstandard (zstd) on the fly and can serve pre-compressed .zst files. Use it next to gzip and Brotli: zstd usually compresses better than gzip, sometimes at a lower encoding speed. This is our hardened, fuzzed fork; see the compression comparison.

Source: our fork on GitHub

Read more: deep-dive article on deb.myguard.nl

Directives

test_ref_probe #

syntax: test_ref_probe no args;  ·  context: location

NGX_CONF_NOARGS: the directive that the scenario confs put in `location /__probe` is bare. A consumer whose probe needs a zone declares its own directive with its own argument spec -- @PROBE@ exists precisely so the scenario tree does not have to know which shape it is.

test_ref_zone #

syntax: test_ref_zone 2 args;  ·  context: http

Optional, http-level: `test_ref_zone <name> <size>;`. Only the zone-name-escaping scenario's conf carries this (via @PROBE_ZONE@); every other scenario conf leaves it out and ngx_http_test_ref_zone stays NULL. NGX_CONF_TAKE2 so the name is its own token and can be a quoted nginx-conf string ("a\"b") -- nginx's own lexer unescapes \", \\ and control-char escapes before this handler ever sees value[1], which is what lets the scenario drive a zone name containing a literal quote, backslash and control character without this module doing any unescaping itself.

zstd #

syntax: zstd on | off;  ·  default: zstd off;  ·  context: http, server, location, if in location

Enables or disables on-the-fly zstd compression for responses. Example: ---

zstd_buffers #

syntax: zstd_buffers number size;  ·  default: zstd_buffers 2 <ZSTD_CStreamOutSize()>; (the size is libzstd's recommended streaming output unit, ~128 KB)  ·  context: http, server, location

Configures the number and size of output buffers used during compression. The total buffer space is number × size. Increasing these values allows larger chunks to be accumulated before writing, potentially improving throughput at the cost of higher per-request memory usage. Example:

zstd_buffers_unsafe #

syntax: zstd_buffers_unsafe on | off;  ·  default: off  ·  context: http, server, location

This directive is intended for operators who have calculated their total concurrency, compressor memory, and output-chain memory budgets and deliberately chosen a buffer configuration above the safety threshold. If you are not sure whether you need this, leave it off — the hard error is the safer default. Example: ---

zstd_bypass #

syntax: zstd_bypass string ...;  ·  default: —  ·  context: http, server, location

Disables on-the-fly compression for the current request when at least one of the given string parameters evaluates to a non-empty value that is not "0". Each parameter is typically a variable (often driven by a map), so the decision is made per request rather than statically. > > > > ---

zstd_bypass_vary #

syntax: zstd_bypass_vary field-name;  ·  default: —  ·  context: http, server, location

Appends field-name to the response Vary header on every response for which this module actually reaches the zstd_bypass decision — both the compressed variant and the bypassed-identity variant — so a shared cache keys on the request header that drives a header/cookie-based eligibility gate (ineligible status, already encoded, below ---

zstd_comp_level #

syntax: zstd_comp_level level;  ·  default: zstd_comp_level 3;  ·  context: http, server, location

Sets the zstd compression level. Accepted values depend on the installed zstd library version: Choosing a level: For most web-serving workloads, levels 1–3 are recommended. Avoid high levels (> 9) in production unless responses are generated infrequently and cached. Example: ---

zstd_dcz_assume_secure_transport #

syntax: zstd_dcz_assume_secure_transport on | off;  ·  default: zstd_dcz_assume_secure_transport off;  ·  context: http, server, location

Asserts that the client-facing hop is TLS even though this nginx sees plaintext, re-enabling dcz negotiation on a non-TLS connection. When TLS is terminated by a load balancer or CDN in front of this nginx, the connection nginx sees is plaintext and the check fires even though the client spoke HTTPS. Set this directive on in that deployment: ---

zstd_dcz_dict_file #

syntax: zstd_dcz_dict_file /path/to/dictionary [sha256hex];  ·  default: —  ·  context: http, server, location (repeatable)

The module handles the response side; advertising the dictionary to clients is one add_header on the dictionary resource (usually the resource itself, so today's file becomes the dictionary for tomorrow's): Operational notes: Verify a response end-to-end with the zstd CLI (the 40-byte header is a valid skippable frame, so no stripping is needed): ---

zstd_dcz_dict_trust_hashes #

syntax: zstd_dcz_dict_trust_hashes on | off;  ·  default: off  ·  context: http

Example (content-addressed deployment with optimized hashing): ---

zstd_dict_file #

syntax: zstd_dict_file /path/to/dict;  ·  default: —  ·  context: http

Loads a pre-trained zstd dictionary for use during compression. Dictionaries can significantly improve compression ratios for small, structurally similar responses (e.g. JSON API responses). Example: ---

zstd_dict_file_unsafe #

syntax: zstd_dict_file_unsafe on | off;  ·  default: off  ·  context: http

nginx refuses to start if zstd_dict_file is configured without zstd_dict_file_unsafe on;, acknowledging that you control both ends of the connection (client and server) and will ensure the shared cache keys the response appropriately (or is absent). Example: See zstd_dict_file for an example that includes this directive. ---

zstd_dict_strict_path #

syntax: zstd_dict_strict_path on | off;  ·  default: off  ·  context: http

Example (hardened, content-addressed dictionary path): ---

zstd_long #

syntax: zstd_long on | off;  ·  default: zstd_long off;  ·  context: http, server, location

Enables zstd long-distance matching (ZSTD_c_enableLongDistanceMatching). zstd keeps a secondary long-range hash table that finds repeated sequences far beyond the regular match window, which can meaningfully improve the compression ratio on large, internally repetitive bodies — concatenated JSON, HTML with repeated boilerplate, log dumps, sitemaps. Example:

zstd_max_cctx_memory #

syntax: zstd_max_cctx_memory size;  ·  default: — (no budget enforced; see [the advisory](#implicit-advisory-when-no-budget-is-set) below)  ·  context: http, server, location

Requires: module built with -DZSTD_STATIC_LINKING_ONLY against libzstd ≥ 1.4.0. This is not the result of the plain ./configure --add-dynamic-module=... command in Installation — that auto-discovers a dynamic libzstd and never defines the flag. It is only set when ZSTD_INC/ZSTD_LIB point at a static libzstd build; see Installation and Compatibility.

zstd_max_length #

syntax: zstd_max_length length;  ·  default: — (no limit)  ·  context: http, server, location

Sets the maximum response size that will be compressed. The limit is enforced in two places: By default there is no upper limit. You may want to set one if very large responses (e.g. multi-megabyte file downloads) should bypass compression to avoid holding the worker process busy. Example: ---

zstd_min_length #

syntax: zstd_min_length length;  ·  default: zstd_min_length 1024;  ·  context: http, server, location

Sets the minimum response size (in bytes) required for compression to apply. The size is taken from the Content-Length response header; responses without Content-Length are always eligible. Example: ---

zstd_probe #

syntax: zstd_probe no args;  ·  context: location

zstd_static #

syntax: zstd_static on | off | always;  ·  default: zstd_static off;  ·  context: http, server, location

Controls how pre-compressed .zst files are served. > Example: Pre-compress files with a matching level to your workload:

zstd_static_dict_bypass #

syntax: zstd_static_dict_bypass on | off;  ·  default: zstd_static_dict_bypass off;  ·  context: http, server, location

When enabled, zstd_static stands aside for a main request that carries any Available-Dictionary header and explicitly accepts dcz with a non-zero weight. This lets zstd_dcz_dict_file negotiate a dictionary response instead of having the content-phase static handler serve the plain .zst sidecar first. The check applies in both zstd_static on and ---

zstd_target_cblock_size #

syntax: zstd_target_cblock_size size;  ·  default: — (disabled, uses ZSTD library defaults)  ·  context: http, server, location

Requires: libzstd ≥ v1.5.6 Sets the target compressed block size for zstd frames. Controlling block size improves incremental response parsing, particularly in browsers where CSS/JavaScript in the response head must be available as soon as possible. Example: ---

zstd_types #

syntax: zstd_types mime-type ...;  ·  context: http, server, location

When omitted, the default covers common textual web representations. If set explicitly, it follows nginx's usual type-directive behaviour: text/html is included along with the listed MIME types. Use * to match all MIME types. Example for a typical web application: ---

zstd_window_log #

syntax: zstd_window_log exponent;  ·  default: — (disabled; zstd uses its level-derived default)  ·  context: http, server, location

Caps the zstd compression window at 2^exponent bytes. zstd's per-request working memory is dominated by the window size (roughly the window plus match-table overhead), so without a cap a high compression level on large response bodies lets each concurrent request inflate the worker's resident memory unpredictably. Bounding window_log gives a Example: ---

Example

    location /t {
        zstd on;
        zstd_comp_level 9;
        zstd_long on;
        zstd_dcz_dict_file $TEST_NGINX_PERL_PATH/suite/test;
        zstd_dcz_dict_file $TEST_NGINX_PERL_PATH/suite/dcz-dict;
        zstd_min_length 1;
        zstd_types text/plain;
        default_type text/plain;
        return 200 "the quick brown fox jumps over the lazy dog, again";
    }

↑ back to index