Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Migrating from tokers/zstd-nginx-module

ngx_mzstd provides the same two modules, directives, defaults and variable as tokers/zstd-nginx-module, so an existing configuration keeps working unchanged.

Steps

  1. Remove tokers/zstd-nginx-module’s package (nginx-module-zstd, or the distribution’s own) or its load_module lines. Its two .so files become one.

  2. Install or build ngx_mzstd and load it:

    load_module modules/ngx_mzstd.so;
    
  3. Run nginx -t and reload. The rest of the configuration stays as it is.

The libzstd C library is no longer needed by NGINX once nothing else uses it.

What behaves differently

  • The window is limited to 8 MB by default (zstd_window). The C module never declares a response’s length, so levels 20–22 declare windows of 32, 64 and 128 MB on every response, however short, and browsers reject them. Here they stay within 8 MB, where long responses compress exactly as at level 19, as they do with the C library given the same window.
  • The length comes from Content-Length. When it is known, it is declared to the encoder, which writes it into the frame header and chooses its parameters for that size, so short responses use smaller windows and tables. The C module never declares it, so its output differs on such responses. A response whose body does not match its declared length is aborted.
  • Accept-Encoding is parsed more strictly. zstd;q=0 is a refusal, and only a whole zstd token counts: the C module accepts any header that starts with zstd, such as zstdx.
  • zstd_comp_level -1 works. The C module takes -1 for “unset” and compresses at level 1 instead.
  • zstd_dict_file can be set per server and location, and turned off with off. A Zstandard-format dictionary is checked when the configuration is loaded.
  • Encoders are reused by default (zstd_reuse_memory), each keeping all of its working memory between responses (zstd_retention_policy). Set zstd_reuse_memory off to allocate per response as the C module does. See Memory and encoder reuse.
  • Responses can be compressed on a thread pool (zstd_thread_pool), in segments that are compressed in parallel. See Compressing on a thread pool.
  • The pure-Rust mzstd encoder replaces the C library. Driven with the same calls and parameters, it writes the same bytes as zstd 1.6.0; output compressed on a thread pool is a valid frame but differs.

New directives

DirectiveContextDefault
zstd_windowhttp, server, location8m
zstd_reuse_memoryhttp, server, locationon
zstd_retention_policyhttp, server, locationaggressive
zstd_idle_encodershttp4
zstd_thread_poolhttp, server, locationoff
zstd_parallel_segment_sizehttp, server, location1m
zstd_parallel_taskshttp, server, location4
zstd_parallel_compressorshttp4

Reporting a difference

If the module behaves differently from tokers/zstd-nginx-module with the same configuration, and the difference is not listed above, open an issue with the Differs from tokers/zstd-nginx-module template.