如何在NGINX配置中指定不带扩展名的文件的模仿类型? [英] How to specify mimetype of files with no extension in NGINX config?
本文介绍了如何在NGINX配置中指定不带扩展名的文件的模仿类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一台带有Nginx的服务器.而且我有很多图像-png和jpg保存为没有扩展名的文件(例如"123123123_321312").
I have a server with nginx. And I have a lot of images - pngs and jpgs saved as files with no extension (like "123123123_321312").
当我在html页面中使用标签"img"时,会在控制台中收到这些消息:
When I use tag "img" in html page, I get theese messages in console:
Resource interpreted as Image but transferred with MIME type application/octet-stream: "http://xxxx/images/1350808948_997628". jquery.js:2
Resource interpreted as Image but transferred with MIME type application/octet-stream: "http://xxxx/images/1343808569_937350".
有没有办法使nginx添加具有所请求文件的正确mimetype的标头?
Is there a way to make nginx add header with correct mimetype of the requested file?
推荐答案
您应使用 default_type
指令:
You should use the default_type
directive :
server {
...
default_type text/html;
location /images/png {
default_type image/png;
}
location /images/jpg {
default_type image/jpeg;
}
}
这篇关于如何在NGINX配置中指定不带扩展名的文件的模仿类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文