Force nginx to send specific Content-Type

NginxHttp HeadersContent Type

Nginx Problem Overview


How to overwrite default Content-Type in nginx? Currently when I request 01.dae file, there's

Content-Type: application/octet-stream;

And I want it to be

Content-Type: application/xml;

I tried something like

location ~* \.dae$ {
  types { };
  default_type application/xml;
}

and

location ~* \.dae$ {
  add_header Content-Type application/xml;
}

but nothing works.

Nginx Solutions


Solution 1 - Nginx

In case you have no file extension:

location ~ something {
   default_type application/xml;
}

Nginx docs for default_type

In case you are setting up let's encrypt certificate with a client which creates http server: https://stackoverflow.com/questions/40502926/how-to-use-golang-lego-lets-encrypt-client-behind-nginx

Solution 2 - Nginx

You can edit /etc/nginx/mime.types and add it

types {
    application/xml        dae;
}

I haven't found the the exact string application/xml in my mime.types so I suppose you can directly include it inside your server block, in the server scope or something.

Solution 3 - Nginx

Add "the application/xml dae;" to your server scope or location scope. Or add it into the mime.type.

Both of them work for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKasheftinView Question on Stackoverflow
Solution 1 - NginxOleg NeumyvakinView Answer on Stackoverflow
Solution 2 - NginxMohammad AbuShadyView Answer on Stackoverflow
Solution 3 - Nginxguo simonView Answer on Stackoverflow