Search code examples
nginxsvgmime-typesmime

NGINX - Can't set content-type header


I'm using nginx/1.10-3 on Debian.

I have a file named logo.img which infact is an svg.

I've modified /etc/nginx/mime.types to include the .img as an extension for the svg file type: image/svg+xml svg svgz img;

But the headers of the file served is still application/octet-stream

For some bizarre reason, i've been asked to serve the .img file as an svg for a logo on a site, i've got it to work on Apache2 using mime magic. But, as far as i know, that doesn't exist on NGINX.


Solution

  • The /etc/nginx/mime.types file already contains a mapping for URIs ending with .img, which is set to application/octet-stream.

    When you edit the file, did must also remove this existing mapping.


    Alternatively, you can override the content-type for a single URI.

    For example:

    root /path/to/root;
    ...
    location = /images/logo.img {
        types {}
        default_type image/svg+xml;
    }