Nginx
Gzip Compression
Compress text responses to reduce bandwidth.
By EZ4Code Team
gzipcompressionperformance
Code
# http block
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
# Brotli (requires ngx_brotli module)
# brotli on;
# brotli_comp_level 6;
# brotli_types text/plain text/css application/json;
# Verify with:
# curl -sH 'Accept-Encoding: gzip' -I https://example.com/file.cssExplanation
gzip compresses text responses, dramatically reducing transfer size for HTML, CSS, JS, and JSON. gzip_comp_level balances CPU versus compression ratio; 6 is a sane default. Set gzip_min_length to skip tiny responses where overhead exceeds savings, and gzip_types to opt in non-text MIME types.
More Nginx Snippets
Server Block
Configure a virtual host with root, index, and try_files.
Reverse Proxy
Forward requests to upstream HTTP services.
Load Balancing
Distribute traffic across multiple upstream servers.
HTTPS & SSL
Terminate TLS with certificates and HTTP/2.
Location Rules
Match request URIs with prefix, regex, and exact locations.
Rewrite & Redirect
Rewrite URIs and issue HTTP redirects.