FAQ

Page Discussion Edit History

NginxHttpGzipModule

Contents

Edit section: Synopsis Synopsis

This module allows for on-the-fly gzip compression. See also Gzip pre-compression module .

Example

  gzip             on;
  gzip_min_length  1000;
  gzip_proxied     expired no-cache no-store private auth;
  gzip_types       text/plain application/xml;
  gzip_disable     "MSIE [1-6]\.";

Compression ratio is available via the variable $gzip_ratio.

Edit section: Directives Directives

Edit section: gzip gzip

syntax: gzip on|off

default: gzip off

context: http, server, location, if (x) location

Enables or disables gzip compression.


Edit section: gzip_buffers gzip_buffers

syntax: gzip_buffers number size

default: gzip_buffers 4 4k/8k

context: http, server, location

Assigns the number and the size of the buffers into which to store the compressed response. If unset, the size of one buffer is equal to the size of page, depending on platform this either 4K or 8K.


Edit section: gzip_comp_level gzip_comp_level

syntax: gzip_comp_level 1..9

default: gzip_comp_level 1

context: http, server, location

The compression level, between 1 and 9, where 1 is the least compression (fastest) and 9 is the most (slowest).


Edit section: gzip_disable gzip_disable

syntax: gzip_disable regex

context: http, server, location

Disable gzip compression for User-Agents matching the given regular expression. Requires PCRE library. Introduced in Nginx 0.6.23.


Edit section: gzip_http_version gzip_http_version

syntax: gzip_http_version 1.0|1.1

default: gzip_http_version 1.1

context: http, server, location

Turns gzip compression on or off depending on the HTTP request version.

When HTTP version 1.0 is used, the Vary: Accept-Encoding header is not set. As this can lead to proxy cache corruption, consider adding it with add_header . Also note that the Content-Length header is not set when using either version. Keepalives will therefore be impossible with version 1.0, while for 1.1 it is handled by chunked transfers.


Edit section: gzip_min_length gzip_min_length

syntax: gzip_min_length length

default: gzip_min_length 0

context: http, server, location

Sets the minimum length of of the response that will be compressed. Responses shorter than this will not be compressed. Length is determined from the "Content-Length" header.


Edit section: gzip_proxied gzip_proxied

syntax: gzip_proxied [off|expired|no-cache|no-store|private|no_last_modified|no_etag|auth|any] ...

default: gzip_proxied off

context: http, server, location

It allows or disallows the compression of the response for the proxy request in the dependence on the request and the response. The fact that, request proxy, is determined on the basis of line "Via" in the headers of request. In the directive it is possible to indicate simultaneously several parameters:

  • off - disables compression for all proxied requests
  • expired - enables compression, if the "Expires" header prevents caching
  • no-cache - enables compression if "Cache-Control" header is set to "no-cache"
  • no-store - enables compression if "Cache-Control" header is set to "no-store"
  • private - enables compression if "Cache-Control" header is set to "private"
  • no_last_modified - enables compression if "Last-Modified" isn't set
  • no_etag - enables compression if there is no "ETag" header
  • auth - enables compression if there is an "Authorization" header
  • any - enables compression for all requests


Edit section: gzip_types gzip_types

syntax: gzip_types mime-type [mime-type ...]

default: gzip_types text/html

context: http, server, location

Enables compression for additional MIME-types besides "text/html". "text/html" is always compressed.


Edit section: gzip_vary gzip_vary

syntax: gzip_vary on|off

default: gzip_vary off

context: http, server, location

Enables response header of "Vary: Accept-Encoding". Note that this header causes IE 4-6 not to cache the content due to a bug (see [1] ).

Edit section: References References

Original Documentation