Nginx gzip_types Explained: MIME Types, Configuration, and Best Practices

Published: 2026-07-14

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

Operating System : AlmaLinux 10
PHP Version      : PHP 8.3
Web Server       : Nginx
PHP-FPM          : Enabled
Architecture     : x86_64
Last Tested      : July 2026

What Is gzip_types?

The gzip_types directive defines the MIME types that Nginx compresses before sending responses to clients.

Example:

http {
    gzip on;
    gzip_types
        text/css
        application/javascript
        application/json;
}

Only responses with matching MIME types are compressed.

Relationship with gzip

The two directives work together.

Client Request
       │
       ▼
     Nginx
       │
       ▼
gzip on?
       │
   Yes │
       ▼
Match gzip_types?
       │
 ┌─────┴─────┐
 │           │
Yes         No
 │           │
 ▼           ▼
Compress   Send Original

If gzip is disabled, gzip_types has no effect.

Common MIME Types

The following MIME types are commonly compressed.

gzip_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/javascript
    application/json
    application/xml
    application/rss+xml
    application/xhtml+xml
    image/svg+xml;

These formats are primarily text and usually compress very well.

Recommended Configuration

http {

    gzip on;

    gzip_types
        text/plain
        text/css
        text/javascript
        application/javascript
        application/json
        application/xml
        application/rss+xml
        application/xhtml+xml
        image/svg+xml;

}

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:

image/jpeg
image/png
image/webp
image/gif
video/mp4
application/zip
application/x-7z-compressed
application/pdf

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.

grep -R gzip_types /etc/nginx

Example output:

gzip_types text/plain text/css application/json;

Test the Configuration

After modifying the configuration:

sudo nginx -t

Expected output:

nginx: the configuration file syntax is ok

nginx: configuration file test is successful

Reload Nginx

Apply the changes.

sudo systemctl reload nginx

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:

gzip_types
    image/jpeg
    image/png;

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.

gzip on;
gzip_types
    text/css
    application/javascript;

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

Technology Guides →

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

Southeast Asia Insights →

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