gzip
#
描述gzip
插件能动态设置 NGINX 的压缩行为。
IMPORTANT
该插件要求 Apache APISIX 运行在 APISIX-Base 上。
#
属性名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
---|---|---|---|---|---|
types | array[string] or "*" | 否 | ["text/html"] | 动态设置 gzip_types 指令,特殊值 "*" 匹配任何 MIME 类型。 | |
min_length | integer | 否 | 20 | >= 1 | 动态设置 gzip_min_length 指令。 |
comp_level | integer | 否 | 1 | [1, 9] | 动态设置 gzip_comp_level 指令。 |
http_version | number | 否 | 1.1 | 1.1, 1.0 | 动态设置 gzip_http_version 指令。 |
buffers.number | integer | 否 | 32 | >= 1 | 动态设置 gzip_buffers 指令。 |
buffers.size | integer | 否 | 4096 | >= 1 | 动态设置 gzip_buffers 指令。 |
vary | boolean | 否 | false | 动态设置 gzip_vary 指令。 |
#
启用插件以下示例展示了如何在指定路由中启用 gzip
插件:
curl -i http://127.0.0.1:9080/apisix/admin/routes/1 \-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ "uri": "/index.html", "plugins": { "gzip": { "buffers": { "number": 8 } } }, "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:1980": 1 } }}'
#
测试插件通过上述命令启用插件后,可以使用如下命令测试插件是否启用成功:
curl http://127.0.0.1:9080/index.html -i -H "Accept-Encoding: gzip"
HTTP/1.1 404 Not FoundContent-Type: text/html; charset=utf-8Transfer-Encoding: chunkedConnection: keep-aliveDate: Wed, 21 Jul 2021 03:52:55 GMTServer: APISIX/2.7Content-Encoding: gzip
Warning: Binary output can mess up your terminal. Use "--output -" to tellWarning: curl to output it to your terminal anyway, or consider "--outputWarning: <FILE>" to save to a file.
#
禁用插件当你需要禁用 gzip
插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
curl http://127.0.0.1:9080/apisix/admin/routes/1 \-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{ "uri": "/index.html", "upstream": { "type": "roundrobin", "nodes": { "127.0.0.1:1980": 1 } }}'