How to enable nginx slice module?
How to enable nginx slice module?
With nginx 1.9.8 mainline, nginx introduced a new module “ngx_http_slice_module”. Nginx slice module enables the slicing of large response like video files, and improves the “cache-ability” of these large requests. This module is not built into nginx by default, so we have to enable this module while building nginx from source.
How to Enable nginx slice ( ngx_http_slice_module ) module?
We can use the “–with-http_slice_module” configuration parameter to enable slice module
1 2 3 4 5 6 7 | wget http://nginx.org/download/nginx-1.11.9.tar.gz cd nginx–1.11.9 ./configure —with–http_slice_module make make install |
Once installation is successful, you can verify it using
1 2 3 4 5 6 7 8 | [root@test.test.com nginx–1.11.9]# nginx -V nginx version: nginx/1.10.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7–17) (GCC) built with OpenSSL 1.0.1e–fips 11 Feb 2013 TLS SNI support enabled configure arguments: —prefix=/usr/share/nginx —sbin–path=/usr/sbin/nginx —modules–path=/usr/lib64/nginx/modules —conf–path=/etc/nginx/nginx.conf —error–log–path=/var/log/nginx/error.log —http–log–path=/var/log/nginx/access.log —http–client–body–temp–path=/var/lib/nginx/tmp/client_body —http–proxy–temp–path=/var/lib/nginx/tmp/proxy —http–fastcgi–temp–path=/var/lib/nginx/tmp/fastcgi —http–uwsgi–temp–path=/var/lib/nginx/tmp/uwsgi —http–scgi–temp–path=/var/lib/nginx/tmp/scgi —pid–path=/var/run/nginx.pid —lock–path=/var/lock/subsys/nginx —user=nginx —group=nginx —with–file–aio —with–ipv6 —with–http_ssl_module —with–http_v2_module —with–http_realip_module —with–http_addition_module —with–http_xslt_module=dynamic —with–http_image_filter_module=dynamic —with–http_geoip_module=dynamic —with–http_sub_module —with–http_dav_module —with–http_flv_module —with–http_mp4_module —with–http_gunzip_module —with–http_gzip_static_module —with–http_random_index_module —with–http_secure_link_module —with–http_degradation_module —with–http_slice_module —with–http_stub_status_module —with–http_perl_module=dynamic —with–mail=dynamic —with–mail_ssl_module —with–pcre —with–pcre–jit —with–stream=dynamic —with–stream_ssl_module —with–debug —with–cc–opt=‘-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector –param=ssp-buffer-size=4 -m64 -mtune=generic’ —with–ld–opt=‘ -Wl,-E’ |
How to configure the “ngx_http_slice_module” module?
Sample configuration for using slice module is below
1 2 3 4 5 6 7 8 9 10 | location / { slice 1m; proxy_cache cache; proxy_cache_key $uri$is_args$args$slice_range; proxy_set_header Range $slice_range; proxy_cache_valid 200 206 1h; proxy_pass http://localhost:8000; } |
In the above configuration, nginx acts as a reverse proxy. When a request arrives , Nginx proxies request to backend server and send back the response to the client. Also Nginx caches the responses inside its internal cache, so subsequent requests are served from cache directly.
In the case of video files, response size will be large and client access the files using byte‑range requests ( Requests for particular byte-range of the video file intead of entire file) . With “ngx_http_slice_module” module, nginx breaks the file into smaller segments and requests each segment from backend whenever it is required. The segments are accumulated in the cache, and requests for the resource are satisfied by delivering appropriate parts of one or more segments to the client. When there is a request for entire file, Nginx assembles the response from all segments in the cache and send back to the client.