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.
This is a module that is distributed with Tengine which is a distribution of NGINX that is used by the e-commerce/auction site Taobao.com. This distribution contains some modules that are new on the NGINX scene. The ngx_http_slice_module
module is one of them.
This module can be thought out as a reverse byte-range request header. It’s main utility is to allow NGINX to slice a big file in small pieces (byte-ranges) while permitting to use on-the-fly gzip compression.
A typical example is for allowing someone to download a large video file while keeping the bandwith usage minimal. This might also be used as device for selling a video file by pieces where each link points to different zones of the file splitted by file ranges.
Other use would be to use a generic CSS file and use only part of it for each section of a site. Granted that byte-range slicing isn’t the most intuitive for such.
Note also that using arguments is more useful than byte-ranges in the sense that they can be set in a normal link, while byte ranges require a special HTTP header.
Configuration example:
location ^~ /video-dump/ {
slice; # enable slicing
slice_start_arg s;
slice_end_arg e;
}
So we would request the first 1k of the file like this:
http://example.com/video-dump/large_vid.mp4?s=0&e=1024
Note
s=0
, start at 0 and e=1024
, stop at 1024 bytes (1k).
This documentation was originally written by António P. P. Almeida
Syntax: | slice |
---|---|
Default: | none |
Context: | location |
It enables the content slicing in a given location.
Syntax: | slice_arg_begin string |
---|---|
Default: | start |
Context: | http, server, location |
Defines the argument that defines the request range of bytes start.
Syntax: | slice_arg_end string |
---|---|
Default: | end |
Context: | http, server, location |
Defines the argument that defines the request range of bytes end.
Syntax: | slice_header string |
---|---|
Default: | none |
Context: | http, server, location |
Defines the string to be used as the header of each slice being served by NGINX.
Syntax: | slice_header_first [on|off] |
---|---|
Default: | on |
Context: | http, server, location |
If set to off
and when requesting the first byte of the file do not serve the header.
This directive is particularly useful to differentiate the first slice from the remaining slices. The first slice is the one which has no header.
Here’re some examples that explore all the options.
location ^~ /dbdumps/ { slice; # enable slicing slice_start_arg first; slice_end_arg last; slice_header '-- **db-slice-start**'; slice_header_first off; }Then a request like this:
http://example.com/dbdumps/somedb.sql?first=0&last=1048576Send the first 1M and skip the
*-- **db-slice-start*** header
.
location ^~ /dbdumps/ { slice; # enable slicing slice_start_arg first; slice_end_arg last; slice_header '-- **db-slice-start**'; slice_header_first off; slice_footer '-- **db-slice-end**'; }This differs from the previous in the sense that it sends a footer.
location ^~ /dbdumps/ { slice; # enable slicing slice_start_arg first; slice_end_arg last; slice_header '-- **db-slice-start**'; slice_header_first off; slice_footer '-- **db-slice-end**'; slice_footer_last off; }Then a request like this:
http://example.com/dbdumps/somedb.sql?first=0&last=1048576Send the first 1M and skip the
*-- **db-slice-start*** header
.If the file is 200MB, we get the last slice with:
http://example.com/dbdumps/somedb.sql?first=208666624&last=209715200this last slice has no footer.
--add-module=/path/to/nginx-http-slice
<a href="http://example.com/datadumps/dump0.sql?start=0&end=4096"/>db dump</a>
Thanks to Joshua Zhu and the Taobao platform engineering team for releasing tengine.
Copyright (C) 2010-2012 Alibaba Group Holding Limited
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.