设置服务器的 MIME 类型

发布于 2024-10-30 01:56:20 字数 1303 浏览 0 评论 0原文

我看过很多关于设置 MIME 类型的主题。

但是,没有人帮助我。

他是我的问题:

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

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

问题出在 .ogv 上。

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

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

$ 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:而

$ 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

不是“application/octet-stream”,我需要“video/ogg”。

我最近才知道,我有一个 Mongrel 服务器(没有 Apache 作为前端)。所以,没有办法使用.htaccess。

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

我已经尝试了多种方法,如我之前的问题中所述:HTML 5 视频 (ogv) 和 MIME 类型

但我不起作用。我仍然得到“应用程序/八位字节流”。

我的问题是:

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

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

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

But, no one helped me.

He is my problem:

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.

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

The problem is with .ogv.

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

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

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

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

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

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

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".

My Questions are:

  1. How can i set mime types for regular files, not responses from controller ?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘你却要生生世世 2024-11-06 01:56:20

我已经弄清楚了。

我上一个问题中描述的所有方法都是为 Rails 环境设置 MIME 类型,而不是 Mongrel。

我需要 Mongrel 级别的额外 MIME 类型,而不是 Rails。

因此,通过通过……启动 mongrel

/usr/bin/mongrel_rails,

,我需要将一个 YAML 文件传递​​给它,其中包含我想要声明的其他 MIME 类型。此 YAML 文件可能如下所示 (mongrel_mime_types.yml):

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

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

所以,通过启动 Mongrel,我需要传递这个文件:

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

现在,如果我检查curl,我会得到正确的 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

I've figured it out.

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

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

So, by starting mongrel via …

/usr/bin/mongrel_rails,

… 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

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文