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
-
Remove tokers/zstd-nginx-module’s package (
nginx-module-zstd, or the distribution’s own) or itsload_modulelines. Its two.sofiles become one. -
Install or build ngx_mzstd and load it:
load_module modules/ngx_mzstd.so; -
Run
nginx -tand 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=0is a refusal, and only a wholezstdtoken counts: the C module accepts any header that starts withzstd, such aszstdx. zstd_comp_level -1works. The C module takes -1 for “unset” and compresses at level 1 instead.zstd_dict_filecan be set per server and location, and turned off withoff. 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). Setzstd_reuse_memory offto 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
| Directive | Context | Default |
|---|---|---|
zstd_window | http, server, location | 8m |
zstd_reuse_memory | http, server, location | on |
zstd_retention_policy | http, server, location | aggressive |
zstd_idle_encoders | http | 4 |
zstd_thread_pool | http, server, location | off |
zstd_parallel_segment_size | http, server, location | 1m |
zstd_parallel_tasks | http, server, location | 4 |
zstd_parallel_compressors | http | 4 |
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.