|
AddModule modules/standard/mod_mime_magic.o
これは構築された Configuration ファイルで mod_mime よりも前にリストされるべきで、mod_mime の後に使われるでしょう。mod_mime_magic は mod_mime が解析できない場合について、"second line of defense" となっています。
file(1) コマンドのフリーバージョンに由来します。このモジュールの場合には、ファイルの MIME タイプを判別しようとします。
もしマジックファイルが存在して、サーバのコンフィギュレーション時に首尾よく開かれると、モジュールは最適な動作になります。マジックファイルは MimeMagicFile 命令か、conf/magic に対するデフォルトによって名前が付けられます。
ファイルのコンテンツは、4-5 の欄にあるプレインの ASCII テキストです。ブランク行は許可されますが、無視されます。コメントされた行はハッシュマスク"#"を使っています。残りの行は以下の 欄のために解析されます:
| Column | Description | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | byte number to begin checking from
">" indicates a dependency upon the previous non-">" line |
||||||||||||||||||||||
| 2 | type of data to match
|
||||||||||||||||||||||
| 3 | contents of data to match | ||||||||||||||||||||||
| 4 | MIME type if matched | ||||||||||||||||||||||
| 5 | MIME encoding if matched (optional) |
例えば、以下のマジックファイル行は、いくつかのオーディオフォーマットを認識します。
# Sun/NeXT audio data 0 string .snd >12 belong 1 audio/basic >12 belong 2 audio/basic >12 belong 3 audio/basic >12 belong 4 audio/basic >12 belong 5 audio/basic >12 belong 6 audio/basic >12 belong 7 audio/basic >12 belong 23 audio/x-adpcmまたは、これらは Microsoft Word か、または FrameMaker ドキュメントを含んでいる "*.doc" ファイルにある違いを認識します(これらは、同じファイル拡張子を使っているファイルのフォーマットとは互換性がありません)。
# Frame 0 string \<MakerFile application/x-frame 0 string \<MIFFile application/x-frame 0 string \<MakerDictionary application/x-frame 0 string \<MakerScreenFon application/x-frame 0 string \<MML application/x-frame 0 string \<Book application/x-frame 0 string \<Maker application/x-frame # MS-Word 0 string \376\067\0\043 application/msword 0 string \320\317\021\340\241\261 application/msword 0 string \333\245-\0\0\0 application/mswordオプションの MIME エンコーディングは5番目の欄として含まれます。例えば、これは gzip されたファイルを認識し、それらのためにエンコーディングを設定することができます。
# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver) 0 string \037\213 application/octet-stream x-gzip
しかしながら、ビジーなウェブサーバで適合させるオリジナルファイル(1)コードのパフォーマンスを改良する試みが行われました。それは、彼等自身のドキュメントを発行する数千のユーザがいるサーバのために設計されました。これはイントラネットでは最も一般的なものです。 たとえユーザが不適切にそれら自身のファイルに名前を付けるときに、"なんでページが出てこないのか?" という疑問を減らすためであっても、もしサーバが、ファイル名が許可するよりも、ファイルのコンテンツについてより賢い判断をできるなら、それは役に立ちます。もし余分な仕事があなたの環境に好都合であるなら、決定するべきです。
Apache サーバをコンパイルする時に、このモジュールはコンフィギュレーションファイルのモジュール・リストのトップかその付近にあるべきです。モジュールは増加性の優先度でリストされるので、ちょうど設計されたように最後の手段としてだけ使われるこの一つを意味します。
Syntax: MimeMagicFile magic-file-name
Default: conf/magic
Context: server config, virtual host
Status: Extension
Module: mod_mime_magic
MimeMagicFile 命令は conf/magic での、そのデフォルトのロケーションからマジックファイルのロケーションを変更するために使われます。ルートのないパスは ServerRoot に相対しています。
/* * mod_mime_magic: MIME type lookup via file magic numbers * Copyright (c) 1996-1997 Cisco Systems, Inc. * * This software was submitted by Cisco Systems to the Apache Group in July * 1997. Future revisions and derivatives of this source code must * acknowledge Cisco Systems as the original contributor of this module. * All other licensing and usage conditions are those of the Apache Group. * * Some of this code is derived from the free version of the file command * originally posted to comp.sources.unix. Copyright info for that program * is included below as required. * --------------------------------------------------------------------------- * - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin. * * This software is not subject to any license of the American Telephone and * Telegraph Company or of the Regents of the University of California. * * Permission is granted to anyone to use this software for any purpose on any * computer system, and to alter it and redistribute it freely, subject to * the following restrictions: * * 1. The author is not responsible for the consequences of use of this * software, no matter how awful, even if they arise from flaws in it. * * 2. The origin of this software must not be misrepresented, either by * explicit claim or by omission. Since few users ever read sources, credits * must appear in the documentation. * * 3. Altered versions must be plainly marked as such, and must not be * misrepresented as being the original software. Since few users ever read * sources, credits must appear in the documentation. * * 4. This notice may not be removed or altered. * ------------------------------------------------------------------------- * * For compliance with Mr Darwin's terms: this has been very significantly * modified from the free "file" command. * - all-in-one file for compilation convenience when moving from one * version of Apache to the next. * - Memory allocation is done through the Apache API's pool structure. * - All functions have had necessary Apache API request or server * structures passed to them where necessary to call other Apache API * routines. (i.e. usually for logging, files, or memory allocation in * itself or a called function.) * - struct magic has been converted from an array to a single-ended linked * list because it only grows one record at a time, it's only accessed * sequentially, and the Apache API has no equivalent of realloc(). * - Functions have been changed to get their parameters from the server * configuration instead of globals. (It should be reentrant now but has * not been tested in a threaded environment.) * - Places where it used to print results to stdout now saves them in a * list where they're used to set the MIME type in the Apache request * record. * - Command-line flags have been removed since they will never be used here. * */
The English original manual is here.