设置服务器的MIME类型 [英] Set MIME type for server

查看:351
本文介绍了设置服务器的MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多有关设置MIME类型的主题.

i've seen a bunch of topics about setting the MIME types.

但是,没有人帮助我.

他是我的问题:

我在/public文件夹中有一个Rails网站,其中包含.ogv和.mov格式的一堆视频. 我在HTML5视频标记中引用了这些文件.

I have a Rails website with bunch of video in .ogv and .mov formats, located in /public folder. I refer to these files in HTML5 video tag.

.mov文件没有问题,它们在WebKit浏览器中可以很好地播放.

There is no problem with .mov files, they are played nice in WebKit browsers.

问题出在.ogv.

我认为是因为.ogv的MIME类型错误.

I think, it's because wrong MIME type for .ogv.

这是我得到的.mov(正确)的内容:

Here is what i get for .mov (correct):

$ curl -I http:/mywebsite.com/video.mov

HTTP/1.1 200 OK
Date: Sun, 03 Apr 2011 19:57:41 GMT
ETag: "4d98744c-1bb-87563c0"
Last-Modified: Sun, 03 Apr 2011 13:21:16 GMT
Content-Type: video/quicktime
Content-Length: 443

这是我得到的.ogv的结果:

And here is what i get for .ogv:

$ curl -I http://mywebsite.com/video.ogv

HTTP/1.1 200 OK
Date: Sun, 03 Apr 2011 19:22:20 GMT
ETag: "4d987dcf-379884-81c533dc"
Last-Modified: Sun, 03 Apr 2011 14:01:51 GMT
Content-Type: application/octet-stream
Content-Length: 3643524

我需要的是"video/ogg",而不是"application/octet-stream".

Instead of "application/octet-stream" i need "video/ogg".

我最近知道,我有一个Mongrel服务器(前端没有Apache).因此,无法使用.htaccess.

I have a Mongrel server (no Apache as front-end), as i recently got to know. So, there is no way to use .htaccess.

我需要为常规文件设置MIME类型,来自控制器的响应等.

I need to set MIME-type for regular files, not responses from controller etc.

我已经尝试了几种方法,如上一个问题所述: HTML 5视频(ogv)和MIME类型

I've tried several ways, described in my previous question: HTML 5 video (ogv) and MIME types

但是我不工作.我仍然收到应用程序/八位字节流".

But i does't works. I still get "application/octet-stream".

我的问题是:

  1. 如何设置常规文件的mime类型,来自控制器的响应?

Mongrel是否提供/public目录中的文件或其他文件?

Does Mongrel serves files, located in /public directory, or something else ?

推荐答案

我已经弄清楚了.

在我之前的问题中描述的所有方法都是为Rails环境而不是Mongrel设置MIME类型.

All the methods, described in my previous question are setting MIME-types for Rails environment, not Mongrel.

我需要Mongrel级别的其他MIME类型,而不是Rails.

I need additional MIME-types at Mongrel level, not Rails.

因此,通过...启动杂种动物

So, by starting mongrel via …

/usr/bin/mongrel_rails,

…我需要向其传递一个YAML文件,该文件包含我要声明的其他MIME类型.这个YAML档案可能看起来像这样(mongrel_mime_types.yml):

… I need to pass a YAML file to it, that contains additional MIME-types, i want to declare. This YAML file might look like this (mongrel_mime_types.yml):

.ogv: video/ogg
.ogg: application/ogg
.ogx: application/ogg

为了方便起见,我将其保存在/config/initializers中.

I keep it in /config/initializers, for convenience.

因此,通过启动Mongrel,我需要传递此文件:

So, by starting Mongrel, i need to pass this file:

/usr/bin/mongrel_rails -m /path_to_my_project/http/config/initializers/mongrel_mime_types.yml

现在,如果我检查一下curl,我得到的是正确的MIME:

Now, if i check with curl, I'm getting correct MIME:

$ curl -I http://mywebsite.com/video.ogv

HTTP/1.1 200 OK
Date: Mon, 04 Apr 2011 05:38:01 GMT
ETag: "4d987dcf-379884-81c533dc"
Last-Modified: Sun, 03 Apr 2011 14:01:51 GMT
Content-Type: video/ogg
Content-Length: 3643524

这篇关于设置服务器的MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆