Nginx – How to define a mime type in nginx for tar.bz2 or tar.gz files

mime-typenginx

I tried adding these lines to mime.types:

application/x-gtar tar.gz tgz tar.bz2 tbz2 tbz;
application/x-bzip2 bz2;
application/x-gzip  gz;

But nginx reports "Content-Type: application/x-bzip2" for a tar.bz2 file. How can I fix it?

Additional question: what's the correct mime type for tar.bz2/tbz2 files? Different sources gave me all kinds of different answers: application/x-gtar, application/x-compressed-tar, application/x-bzip-compressed-tar, application/x-tar-bz2, application/x-bzip2, etc.
Same for tar.gz/tgz

Best Answer

There's a disclaimer in /etc/mime.types file:

Note: Compression schemes like "gzip", "bzip", and "compress" are not actually "mime-types". They are "encodings" and hence must not have entries in this file to map their extensions. The "mime-type" of an encoded file refers to the type of data that has been encoded, not the type of encoding.

This means that you should have application/x-tar to map tarballs instead of separate content-type for each compressing method.

You can safely copy it from /etc/mime.types for instance.

Related Topic