Imagine you’re packing for a week-long trip to Hawaii. If you just stuff your clothes into your suitcase without folding, you’ll struggle to close it. But if you fold them neatly and tightly, they take up far less space—and you can fit more.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.




What Can (and Cannot) Be Compressed?
Nginx excels at compressing text-based resources:
| Compressible Formats | Should Not Be Recompressed |
|---|---|
| CSS, HTML, XML, JSON, JS | Audio (MP3), Video (MP4) |
| SVG, RSS, plain text | ZIP, TAR, other archives |
| Even JPEG (minimal gains) | GIF, already-compressed data |
Recompressing already-compressed formats (e.g., MP3, MP4, ZIP) wastes CPU without meaningful size reduction.
Compression Methods in Nginx
Nginx supports two main algorithms:- GZIP (built-in)
- Brotli (module)
GZIP
GZIP is the most ubiquitous compression format, dating back to the 1990s. Files use the.gz extension, and a CLI tool is available on most Linux/Unix systems.

Enabling GZIP in Nginx
Most Nginx installations include these directives (often commented out) in thehttp block of /etc/nginx/nginx.conf:
gzip on;– Enable gzip compressiongzip_vary on;– SendVary: Accept-Encodingheadergzip_comp_level 6;– Balance between speed (1) and size (9)gzip_types– Define which MIME types to compressgzip_proxied any;– Compress responses even when behind a proxy
For a complete list of gzip settings, see the Nginx gzip module documentation.
Brotli
Brotli often achieves higher compression ratios than gzip. Nginx Plus includes Brotli by default, while open-source Nginx requires installing a module.
http block):
- Levels range from 0–11 (default ~4).
brotli_typesshould mirrorgzip_types.
Compiling Nginx with Brotli (Alternative)
nginx.conf.
Verifying Compression
- Open your browser’s Developer Tools and switch to the Network tab.
- Reload the page.
- Click any resource and inspect the Response Headers:

