nginx

Module ngx_http_gzip_module


english
русский

简体中文
עברית
日本語
türkçe

news
about
download
security advisories
documentation
pgp keys
faq
links
books
support
donation

trac
wiki
twitter
nginx.com
Example Configuration
Directives
     gzip
     gzip_buffers
     gzip_comp_level
     gzip_disable
     gzip_min_length
     gzip_http_version
     gzip_proxied
     gzip_types
     gzip_vary

The ngx_http_gzip_module module is a filter that compresses responses using the “gzip” method. This often allows to reduce the size of transmitted data by half or even more.

Example Configuration

gzip            on;
gzip_min_length 1000;
gzip_proxied    expired no-cache no-store private auth;
gzip_types      text/plain application/xml;

The $gzip_ratio variable can be used to log the achieved compression ratio.

Directives

syntax: gzip on | off;
default:
gzip off;
context: http, server, location, if in location

Enables or disables gzipping of responses.

syntax: gzip_buffers number size;
default:
gzip_buffers 32 4k|16 8k;
context: http, server, location

Sets the number and size of buffers used to compress a response. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform.

Until version 0.7.28, four 4K or 8K buffers were used by default.

syntax: gzip_comp_level level;
default:
gzip_comp_level 1;
context: http, server, location

Sets a gzip compression level of a response. Acceptable values are in the 1..9 range.

syntax: gzip_disable regex ...;
default:
context: http, server, location

This directive appeared in version 0.6.23.

Disables gzipping of responses for requests with “User-Agent” header fields matching any of the specified regular expressions.

The special mask “msie6” (0.7.12) corresponds to the regular expression “MSIE [4-6]\.” but works faster. Starting from version 0.8.11, “MSIE 6.0; ... SV1” is excluded from this mask.

syntax: gzip_min_length length;
default:
gzip_min_length 20;
context: http, server, location

Sets the minimum length of a response that will be gzipped. The length is determined only from the “Content-Length” response header field.

syntax: gzip_http_version 1.0 | 1.1;
default:
gzip_http_version 1.1;
context: http, server, location

Sets the minimum HTTP version of a request required to compress a response.

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

Enables or disables gzipping of responses for proxied requests depending on the request and response. The fact that the response is proxied is determined based on the presence of the “Via” request header field. A directive accepts multiple parameters:

off
disables compression for all proxied requests, ignoring other parameters;
expired
enables compression if a response header includes the field “Expires” with a value that disables caching;
no-cache
enables compression if a response header includes the field “Cache-Control” with the parameter “no-cache”;
no-store
enables compression if a response header includes the field “Cache-Control” with the parameter “no-store”;
private
enables compression if a response header includes the field “Cache-Control” with the parameter “private”;
no_last_modified
enables compression if a response header does not include the field “Last-Modified”;
no_etag
enables compression if a response header does not include the field “ETag”;
auth
enables compression if a request header includes the field “Authorization”;
any
enables compression for all proxied requests.

syntax: gzip_types mime-type ...;
default:
gzip_types text/html;
context: http, server, location

Enables gzipping of responses for the specified MIME types in addition to “text/html”. The special value “*” matches any MIME type (0.8.29). Responses with the type “text/html” are always compressed.

syntax: gzip_vary on | off;
default:
gzip_vary off;
context: http, server, location

Enables or disables emitting the “Vary: Accept-Encoding” response header field if the directives gzip, gzip_static, or gunzip are active.