TECH / Серверы и сайты 2 min read

Nginx Warning: duplicate MIME type “text/html” – Cause and Quick Fix

NEMCD Author
Published Sep 15, 2009 · 2 min

After enabling Gzip compression in Nginx and running a config test, you may spot a warning in the terminal or error log: nginx: [warn] duplicate MIME type "text/html". Even though Nginx still starts and serves traffic, the warning points to a redundant line in your configuration.

Nginx web server logo – fixing duplicate MIME type text/html warning

The reason is straightforward: Nginx compresses text/html responses automatically whenever gzip on; is enabled, so listing text/html inside gzip_types tells the server to register the same MIME type twice.

How the Warning Looks

A typical message during nginx -t or inside /var/log/nginx/error.log looks like this:

nginx: [warn] duplicate MIME type "text/html" in /etc/nginx/nginx.conf:42

How to Fix gzip_types Properly

Open the config file mentioned in the warning (usually /etc/nginx/nginx.conf or a snippet in /etc/nginx/conf.d/) and simply remove text/html from the gzip_types directive. A clean, modern Gzip block looks like this:

gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_types
    text/plain
    text/css
    text/xml
    text/javascript
    application/javascript
    application/json
    application/xml
    application/rss+xml
    image/svg+xml
    font/woff2;

If you are not sure which included file defines the directive, search the entire configuration directory in one command:

grep -rn "gzip_types" /etc/nginx/

Then verify the syntax and reload Nginx without dropping active connections:

nginx -t && systemctl reload nginx

A Few Extra Notes on Nginx Gzip

  • HTML stays compressed: removing text/html from gzip_types never disables HTML compression – Nginx always includes it by default.
  • Check Brotli too: if you use the ngx_brotli module, the same rule applies to brotli_types (do not add text/html there either).
  • Avoid double definitions: if you set gzip_types inside both http {} and a specific server {} block, keep it in one place unless a virtual host truly needs custom rules.

Once text/html is removed from gzip_types, nginx -t finishes cleanly with zero warnings and your error log stays free of noise.

Related posts:

Leave a Comment