Zstandard (zstd)#
The module adds support for Zstandard compression of responses, both dynamic (on-the-fly) and static (precompressed files). Compared to gzip, zstd offers higher compression and decompression speeds at comparable or better compression ratios.
The module consists of two components:
http_zstd_filter — for compressing responses dynamically;
http_zstd_static — for serving precompressed files.
Module Loading#
Enable the modules in the main{}
context:
load_module modules/ngx_http_zstd_filter_module.so;
load_module modules/ngx_http_zstd_static_module.so;
Example Configuration#
server {
listen 80 default_server;
zstd_types text/plain text/css;
zstd_min_length 256; # Minimum response size to compress
zstd_comp_level 3; # Compression level (1–22)
# Dynamic compression for static files
location / {
zstd on;
root /usr/share/angie/html;
}
# Dynamic compression for backend responses
location /bk/ {
zstd on;
proxy_pass http://127.0.0.1:8081/;
}
# Serving precompressed .zst files
location /static/ {
zstd_static on;
root /usr/share/angie;
}
}
server {
listen 8081;
location / {
root /usr/share/angie/html;
index index.html;
}
}
How It Works#
You can combine dynamic (zstd on
) and static (zstd_static on
) compression. In this case, the server will first look for a precompressed .zst
file. If it doesn't exist, it will compress the response dynamically.
Compression is only performed when the Accept-Encoding
header includes zstd
, for example:
Accept-Encoding: gzip, zstd
If compression is applied or a precompressed file is found, the following response header is added:
Content-Encoding: zstd
More Information#
Full documentation and source code are available at: tokers/zstd-nginx-module