zstd_static
The `zstd_static` directive enables serving pre-compressed static files using Zstandard compression in NGINX.
Description
The zstd_static directive allows you to serve static files that have been pre-compressed using the Zstandard (zstd) algorithm. When enabled, NGINX will serve these static files directly without re-compressing them, optimizing performance and reducing CPU usage during request handling. This is particularly beneficial for serving large static assets, such as images, JavaScript, or CSS files. When a request for a static file is made, NGINX will check if the file exists in a compressed form and will serve that version if available.
To effectively use the zstd_static directive, static files must be pre-compressed using the Zstandard algorithm and stored in a designated directory. The directive can be used in the http, server, or location contexts, making it flexible for various NGINX configurations. It is important to ensure that clients are capable of handling Zstandard-compressed content, as media types need proper negotiation to take advantage of this feature. Failure to do so may result in clients not receiving the expected compressed content.
Config Example
server {
listen 127.0.0.1:8080;
server_name localhost;
location / {
zstd_static on;
root /path/to/static/files;
}
}Make sure static files are pre-compressed with Zstandard before being served.
Verify that the clients can handle Zstandard-compressed files to avoid compatibility issues.
Ensure the correct file permissions are set on the compressed files for NGINX to access them.