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.
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.
If you do not have access to the system mime.types
then you can set it in the location block if you have access to that.
https://nginx.org/en/docs/http/ngx_http_core_module.html#types
WARNING When you set types
it will overwrite all mime types set in /etc/nginx/mime.types
. To avoid this target specific extensions with a Regular expression location block. Also know that locations can be nested, like so:
server {
# ...
location / {
root /usr/share/nginx/html;
index index.html;
location ~* \.mjs$ {# target only *.mjs files
# now we can safely override types since we are only
# targeting a single file extension.
types {
text/javascript mjs;
}
}
}
}