Accept cookies for analytics, social media, and advertising, or learn more and adjust your preferences. These cookies are on by default for visitors outside the UK and EEA. Privacy Notice.
mod_zip - an HTTP module for NGINX that assembles ZIP archives dynamically. In simple configurations, mod_zip will take a list of files on the local file system and serve them as a single ZIP archive. In more complex setups, mod_zip can stream component files from upstream servers with NGINX’s native proxying code. Unlike many ZIP creation scripts, the process never takes up more than a few KB of RAM at time, even while assembling archives that are (potentially) hundreds of megabytes.
To install, download the source tarball, expand it, and then compile NGINX with the following option:
--add-module=/path/to/mod_zip-1.x
NGINX 0.7.25 or greater is required.
The module has no configuration directives. It is activated when the original response (presumably from an upstream) includes the following HTTP header:
X-Archive-Files: zip
It then scans the response body for a list of files. The syntax is a space-separated list of the file checksum (CRC-32), size (in bytes), location (properly URL-encoded), and file name. One file per line. The file location corresponds to a location in your nginx.conf; the file can be on disk, from an upstream, or from another module. The file name can include a directory path, and is what will be extracted from the ZIP file. Example:
1034ab38 428 /foo.txt My Document1.txt
83e8110b 100339 /bar.txt My Other Document1.txt
Files are retrieved and encoded in order. If a file cannot be found or the file request returns any sort of error, the download is aborted.
If all files in the list have a CRC-32 value, mod_zip will support the “Range” header for the download. Unknown CRC-32’s should be indicated with a dash (“-“), e.g.
- 428 /foo.txt My Document1.txt
- 100339 /bar.txt My Other Document1.txt
You can use the following setup to compose archives from multiple remote servers:
1034ab38 428 /server1/foo.txt My Document1.txt
83e8110b 100339 /server2/bar.txt My Other Document1.txt
location ~ "^/(?<srv>server[12])/(?<file>.*txt)" {
proxy_pass http://$srv.domain.com/$file
}
--with-http-debug flag
Thanks to box.com for sponsoring the initial development of mod_zip and to vtunnel.com for sponsoring byte-range support.