Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force nginx to send specific Content-Type

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.

like image 504
Kasheftin Avatar asked Oct 28 '13 08:10

Kasheftin


People also ask

How does Nginx determine content type?

It is determined by the name of the file actually returned. The try_files statement in your last configuration will return the requested file if it exists, otherwise index. html is returned, and that file has a MIME type of text/html .

What is mime type in nginx?

The default mime. types file from nginx only contains MIME types for more or less common file extensions. And it certainly isn't very common to have json static files. Also, what types should be gzipped? You may include MIME types for all well compressible content that you have on your site.


2 Answers

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: How to use golang lego let's encrypt client behind nginx?

like image 198
Oleg Neumyvakin Avatar answered Oct 15 '22 03:10

Oleg Neumyvakin


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.

like image 27
Mohammad AbuShady Avatar answered Oct 15 '22 05:10

Mohammad AbuShady