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

use*_*420 12 video mime-type apache2 html5 12.04

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

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

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

我的 HTML 页面的代码是这样的:

<video width="320" height="240" 控件>
  <source src="test.mp4" type="video/mp4">
  <source src="test.ogg" type="video/ogg">
</视频> 

请给我建议。

安吉特

小智 13

我将“webm”添加到/etc/mime.types,Apache 也选择了它:

video/webm                                     webm
Run Code Online (Sandbox Code Playgroud)


Nit*_*esh 3

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
Run Code Online (Sandbox Code Playgroud)

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

查看有关如何启用文件的官方文档.htaccess

摘抄:

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

/etc/apache2/sites-available/default
Run Code Online (Sandbox Code Playgroud)

寻找如下所示的部分:

<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>
Run Code Online (Sandbox Code Playgroud)

您需要修改包含AllowOverride None的行以读取AllowOverride All。这告诉 Apache 可以允许.htaccess文件覆盖以前的指令。您必须重新加载 Apache,此更改才会生效:

sudo /etc/init.d/apache2 reload
Run Code Online (Sandbox Code Playgroud)

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. 
Run Code Online (Sandbox Code Playgroud)

要修复,$ sudo nautilus请右键单击带有 s 文件的目录 .htacces,选择“属性”,然后选择“权限”,并为您登录的用户组授予至少读取权限。

有关 的更多信息,请参阅http://httpd.apache.org/docs/2.0/mod/core.html#allowoverrideAllowOverride


dob*_*bey 2

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