untar_file
The `untar_file` directive specifies a file to be extracted from a tar archive in NGINX.
Description
The untar_file directive is used in conjunction with the untar_archive directive to facilitate the extraction and serving of static content directly from tar archives. The primary function of this directive is to specify the path of the file that should be extracted from the tar archive defined by untar_archive.
In the context of NGINX, this directive utilizes complex values, allowing for dynamic resolution of the file name, which can be constructed based on client requests or other variables. This flexibility makes it suitable for scenarios where multiple files may reside in a single archive, and the choice of file is determined by the incoming request. Once the file is specified, the associated archive is read, and the desired content is served directly to the client without creating any temporary files, thus optimizing performance by using zero-copy methods.
The untar_file directive works seamlessly within the specified contexts (http, server, location), enabling developers to configure it as needed based on their server structure and the design of their application. It is essential that the untar_archive is defined prior to untar_file, otherwise an error will occur, indicating that the specified archive cannot be found or accessed.
Config Example
location ~ ^/(.+?\.tar)/(.*)$ {
untar_archive "$document_root/$1";
untar_file "$2";
untar;
}Ensure untar_archive is defined before untar_file, or it will fail to locate the archive.
The directive only supports GET and HEAD requests, so other methods will not work.
Be cautious of file path traversals in user-supplied values as it could lead to security vulnerabilities.