如何为 Apache 网络服务器添加 MIME 类型?

如何为 Apache 网络服务器添加 MIME 类型?

在 ubuntu 中,我正在运行可以运行 mp4 视频的简单 html 页面,我已经配置了 Apache 服务器,并运行了 hello world 的简单测试页面,它运行良好。在 Apache Webserver 中,我读到我们需要将以下代码添加到 httpd.conf 文件或视频文件所在目录中的 .htaccess 文件中。

添加类型视频/ogg .ogv
添加类型视频/mp4 .mp4
添加类型视频/webm .webm

所以我的问题是这个 httpd.conf 或 .htaccess 文件在哪里可用,我是否需要手动创建这些文件或它们存储在某个地方。

我的 HTML 页面代码如下:

<视频宽度="320"高度="240"控制>
  <source src="test.mp4" type="video/mp4">
  <source src="test.ogg" type="video/ogg">
</视频>

请给我一些建议。

安吉特

答案1

我添加了“webm” /etc/mime.types,Apache 也采用了它:

video/webm                                     webm

答案2

Apache 安装所提供服务的默认配置文件是/etc/apache2/sites-enabled/000-default。在使用此文件之前,最好先备份原始文件。

#To make a backup of the original config file:    
sudo cp /etc/apache2/sites-enabled/000-default /etc/apache2/sites-enabled/000-default.orig

每次编辑此文件时,必须重新启动/重新加载 Apache 才能使更改生效 - sudo service apache2 restart(或)sudo service apache2 reload,而 中的更改.htaccess不需要重新启动 Apache。正如 @dobey 提到的,该.htaccess文件位于网站的 DocumentRoot 中。

看看官方文档关于如何启用.htaccess文件。

摘抄:

为了使.htaccess文件按预期工作,您需要编辑此文件:

/etc/apache2/sites-available/default

寻找如下所示的部分:

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
        # Uncomment this directive is you want to see apache2's
        # default start page (in /apache2-default) when you go to /
        #RedirectMatch ^/$ /apache2-default/
</Directory>

您需要修改包含以下内容的行AllowOverride 无读书允许覆盖全部。这告诉 Apache 允许.htaccess文件覆盖先前的指令是可以的。您必须重新加载 Apache,此更改才会生效:

sudo /etc/init.d/apache2 reload

2009.12.08注:在大约一周前下载的 Ubuntu 9.10 (Karmic) 的 LAMP 中,默认配置文件是,/etc/apache2/sites-available/000-default它 除了包含AllowOverride None在下之外。此外,包含 文件的目录默认不授予 Apache 服务器读取权限,导致 Apache 错误<Directory /><Directory /var/www/>/www/var/.htaccess

(13)Permission denied: /var/www/webapp/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable. 

要修复,$ sudo nautilus请右键单击包含 s 文件的目录 .htacces,选择属性,然后选择权限,并授予您以以下身份登录的用户组至少读取的权限。

http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride欲了解更多信息AllowOverride

答案3

.htaccess文件将是您在DocumentRoot网站目录中创建的内容。

相关内容