gzip

Description

The gzip Plugin dynamically sets the behavior of gzip in Nginx.

gzip - 图1IMPORTANT

This Plugin requires APISIX to run on APISIX-Base.

Attributes

NameTypeRequiredDefaultValid valuesDescription
typesarray[string] or “False[“text/html”]Dynamically sets the gzip_types directive. Special value ““ matches any MIME type.
min_lengthintegerFalse20>= 1Dynamically sets the gzip_min_length directive.
comp_levelintegerFalse1[1, 9]Dynamically sets the gzip_comp_level directive.
http_versionnumberFalse1.11.1, 1.0Dynamically sets the gzip_http_version directive.
buffers.numberintegerFalse32>= 1Dynamically sets the gzip_buffers directive.
buffers.sizeintegerFalse4096>= 1Dynamically sets the gzip_buffers directive.
varybooleanFalsefalseDynamically sets the gzip_vary directive.

Enabling the Plugin

The example below enables the gzip Plugin on the specified Route:

  1. curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "uri": "/index.html",
  4. "plugins": {
  5. "gzip": {
  6. "buffers": {
  7. "number": 8
  8. }
  9. }
  10. },
  11. "upstream": {
  12. "type": "roundrobin",
  13. "nodes": {
  14. "127.0.0.1:1980": 1
  15. }
  16. }
  17. }'

Example usage

Once you have configured the Plugin as shown above, you can make a request as shown below:

  1. curl http://127.0.0.1:9080/index.html -i -H "Accept-Encoding: gzip"
  1. HTTP/1.1 404 Not Found
  2. Content-Type: text/html; charset=utf-8
  3. Transfer-Encoding: chunked
  4. Connection: keep-alive
  5. Date: Wed, 21 Jul 2021 03:52:55 GMT
  6. Server: APISIX/2.7
  7. Content-Encoding: gzip
  8. Warning: Binary output can mess up your terminal. Use "--output -" to tell
  9. Warning: curl to output it to your terminal anyway, or consider "--output
  10. Warning: <FILE>" to save to a file.

Disable Plugin

To disable the gzip Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload and you do not have to restart for this to take effect.

  1. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "uri": "/index.html",
  4. "upstream": {
  5. "type": "roundrobin",
  6. "nodes": {
  7. "127.0.0.1:1980": 1
  8. }
  9. }
  10. }'