Nginx gzip_types Explained: MIME Types, Configuration, and Best Practices
Introduction
The gzip_types directive specifies which MIME types Nginx should compress when HTTP gzip compression is enabled.
While the gzip directive turns compression on or off, gzip_types determines exactly which content types are eligible for compression. Proper configuration helps reduce bandwidth usage and improve page load times while avoiding unnecessary CPU overhead.
This guide explains how gzip_types works, which MIME types should be compressed, recommended configuration, and common mistakes.
Test Environment
What Is gzip_types?
The gzip_types directive defines the MIME types that Nginx compresses before sending responses to clients.
Example:
Only responses with matching MIME types are compressed.
Relationship with gzip
The two directives work together.
If gzip is disabled, gzip_types has no effect.
Common MIME Types
The following MIME types are commonly compressed.
These formats are primarily text and usually compress very well.
Recommended Configuration
This configuration is suitable for most websites and web applications.
MIME Types That Should Not Be Compressed
Some file formats are already compressed internally.
Examples include:
Compressing these formats again usually produces little or no reduction in size while consuming additional CPU resources.
Check the Current Configuration
Search the configuration files.
Example output:
gzip_types text/plain text/css application/json;
Test the Configuration
After modifying the configuration:
Expected output:
nginx: the configuration file syntax is ok
nginx: configuration file test is successful
Reload Nginx
Apply the changes.
Verify Compression
One simple way to verify that compression is working is with curl.
curl -I -H "Accept-Encoding: gzip" https://example.com
If compression is enabled, the response headers should include:
Content-Encoding: gzip
Common Issues
HTML Is Compressed but CSS Is Not
This usually means the CSS MIME type is missing from gzip_types.
Example:
gzip_types
application/json;
Since text/css is not listed, CSS files are sent without compression.
Images Are Added to gzip_types
Example:
This generally provides little benefit because these image formats are already compressed.
Forgetting to Enable gzip
Configuring gzip_types alone is not enough.
Both directives are required.
Best Practices
Enable gzip before configuring gzip_types.
Compress only text-based content.
Do not compress already compressed file formats.
Test configuration changes with nginx -t.
Verify the Content-Encoding response header after deployment.
Conclusion
The gzip_types directive controls which MIME types Nginx compresses when gzip is enabled. By compressing text-based content such as HTML, CSS, JavaScript, JSON, and XML, websites can reduce bandwidth consumption and improve page loading performance.
For most production servers, the recommended approach is to compress common text formats while avoiding media files that are already compressed. Combined with appropriate gzip settings, gzip_types helps deliver faster and more efficient web applications.
Explore More
› Nginx Explained: Essential Configuration Directives and Best Practices
› Nginx worker_processes Explained: Configuration, Performance, and Best Practices
› Nginx worker_connections Explained: Configuration, Limits, and Best Practices
› Nginx keepalive_timeout Explained: Configuration, Performance, and Best Practices
› Best Areas to Live in Bangkok in 2026: A Complete Guide for Expats and Digital Nomads
› Best Coworking Spaces in Bangkok 2026: A Guide for Digital Nomads and Remote Workers
› Why Do People in Southeast Asia Love Iced Drinks? The Climate, Culture, and Science Explained
› Best eSIM for Southeast Asia in 2026: Compare the Top Travel eSIMs