untar

The `untar` directive extracts and serves files directly from a tar archive in response to HTTP requests.

Syntaxuntar;
Defaultnone
Contextlocation
Argumentsnone

Description

The untar directive is part of the NGINX HTTP Untar Module, allowing static content to be served directly from tar archives without the need for temporary extraction to disk. This directive works in conjunction with two other directives: untar_archive, which specifies the tar file's location, and untar_file, which indicates the specific file within the tar archive to serve. When a request matches the location defined with the untar directive, NGINX accesses the specified tar archive, extracts the indicated file, and serves it to the client directly from memory, optimizing performance by eliminating the need for intermediate file storage.

The untar process relies on an efficient caching mechanism, allowing NGINX to store information about the archive's contents to speed up subsequent access requests. The module primarily supports standard files and long file names, operating in zero-copy mode, which minimizes data movement and maximizes throughput for serving files. However, it is limited to handling GET and HEAD HTTP methods, and does not support operations such as listing archive contents or handling symbolic links. Users should carefully structure their NGINX configurations to ensure that the untar directive is used correctly to avoid serving unintended files from archives.

Config Example

location ~ ^/(.+?\.tar)/(.*)$ {
    untar_archive "$document_root/$1";
    untar_file "$2";
    untar;
}

Ensure that the tar file specified by untar_archive is accessible and correctly formatted.

Remember to use only valid file paths and names with untar_file to avoid unexpected results.

Be aware that only certain file types are supported; complex tar structures may not be properly handled.

← Back to all directives