启用 ngx_http_slice_module 需在编译时添加 --with-http_slice_module 参数,安装后还需在配置中设置 slice、proxy_cache_key 含 $slice_range、proxy_set_header Range $slice_range 才能生效。

要启用 ngx_http_slice_module,必须在源码编译阶段显式加入支持参数,该模块默认不编译进 Nginx。
编译时添加 --with-http_slice_module
进入 Nginx 源码目录后,执行 ./configure 时需包含该选项:
-
基础启用命令:
./configure --with-http_slice_module -
通常搭配常用模块(如 SSL、gzip、proxy):
./configure --with-http_slice_module --with-http_ssl_module --with-http_gzip_static_module --with-http_proxy_module - 确认模块已列入编译列表:执行
./configure --help | grep slice,应能输出--with-http_slice_module
编译与安装
配置完成后,按标准流程构建:
-
make -j$(nproc)(并行编译,加快速度) sudo make install
安装完毕后,运行 nginx -V 2>&1 | grep -o with-http-slice-module,若输出 with-http-slice-module,说明模块已成功集成。
注意关键点
仅编译启用还不够,后续还需在配置文件中正确使用 slice 指令和配套缓存逻辑,否则模块不会生效。常见遗漏包括:
- 未在
location块中设置slice 1m等大小指令 -
proxy_cache_key中未包含$slice_range - 未配
proxy_set_header Range $slice_range
这些属于运行时配置,和编译启用是两个独立步骤,缺一不可。











