Reputation: 9473
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.
Upvotes: 86
Views: 154887
Reputation: 42849
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;
}
}
}
}
Upvotes: 49
Reputation: 507
location ~* \.dae$ {
types { } default_type "application/xml; charset=utf-8";
}
Upvotes: 6
Reputation: 10292
In case you have no file extension:
location ~ something {
default_type application/xml;
}
In case you are setting up let's encrypt certificate with a client which creates http server: How to use golang lego let's encrypt client behind nginx?
Upvotes: 102
Reputation: 1
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.
Upvotes: -1