Force nginx to send specific Content-Type

2019-01-21 15:52发布

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.

3条回答
贪生不怕死
2楼-- · 2019-01-21 16:27

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.

查看更多
迷人小祖宗
3楼-- · 2019-01-21 16:39

In case when you have no file extension:

location ~ something {
   default_type application/xml;
}

In case you are setup let's encrypt certificate with client which creates http server: How to use golang lego let's encrypt client behind nginx?

查看更多
叼着烟拽天下
4楼-- · 2019-01-21 16:46

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.

查看更多
登录 后发表回答