⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 686-688.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Configuring Apache</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0789717468//-->

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=36//-->

<!--PAGES=686-688//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="683-686.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="688-690.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">MIME Types: <I>AddType</I> and <I>AddEncoding</I>

</FONT></H4>

<P>A fundamental element of the HTTP protocol, and the reason why the Web was so natural as a home for multiple media formats, is that every data object transferred through HTTP had an associated MIME type.

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The origins of MIME (<TT>Multipurpose Internet Mail Extensions</TT>) lie in an effort to standardize the transmission of documents of multiple media through e-mail. Part of the MIME specification was that e-mail messages could contain meta-information in the headers identifying the data being sent. One type of MIME header is <TT>Content-Type</TT>, which states the format or data type the object is in. For example, HTML is given the label &#147;<TT>text/html</TT>,&#148; and JPEG images are given the label &#147;<TT>image/jpeg</TT>.&#148;<HR></FONT>

</BLOCKQUOTE>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>ON THE WEB:&nbsp;&nbsp;</B><BR>A registry of MIME types is maintained by the Internet Assigned Numbers Authority at this site:

<A HREF="http://www.isi.edu/div7/iana/">http://www.isi.edu/div7/iana/</A><HR></FONT>

</BLOCKQUOTE>

<P>When a browser asks a server for an object, the server gives that object to the browser and states what its <TT>Content-Type</TT> is. That way, the browser can make an intelligent decision about how to render the document. For example, it can send it to an image program, to a PostScript viewer, or to a VRML viewer.</P>

<P>What this means to the server maintainer is that every object being served out must have the right MIME type associated with it. Fortunately, there has been a convention of expressing data type through two-, three-, or four-letter suffixes to the filename&#151;for example, foobar.gif is most likely to be a GIF image.</P>

<P>What the server needs is a file to map the suffix to the MIME content type. Fortunately, Apache comes with such a file in its configuration directory&#151;a file named mime.types. The simple format of this file consists of one record per line, where a record is a MIME type and a list of acceptable suffixes. Although more than one suffix may map to a particular MIME type, you can&#146;t have more than one MIME type per suffix. You can use the <TT>TypesConfig</TT> directive to specify an alternative location for the file.</P>

<P>The Internet is evolving so quickly that it would be hard to keep the mime.types file completely up-to-date. To overcome this difficulty, you can use a special directive, <TT>AddType</TT>, which can be put in the srm.conf file as follows:</P>

<!-- CODE SNIP //-->

<PRE>

AddType x-world/x-vrml wrl

</PRE>

<!-- END CODE SNIP //-->

<P>Now, whenever the server is asked to serve a file that ends with .wrl, it knows to also send a header like the following:

</P>

<!-- CODE SNIP //-->

<PRE>

Content-type: x-world/x-vrml

</PRE>

<!-- END CODE SNIP //-->

<P>Thus, you don&#146;t have to worry about reconciling future distributions of the mime.types file with your private installations and configuration.

</P>

<P>As you&#146;ll see in later pages, <TT>AddType</TT> is also used to specify &#147;special&#148; files that get magically handled by certain features within the server.</P>

<P>A sister to <TT>AddType</TT> is <TT>AddEncoding</TT>. Just as the MIME header <TT>Content-Type</TT> can specify the data format of the object, the <TT>Content-Encoding</TT> header specifies the <I>encoding</I> of the object. An encoding is an attribute of the object as it&#146;s being transferred or stored; semantically, the browser should know that it has to &#147;decode&#148; whatever it gets, based on the listed encoding. The most common use is with compressed files. For example, if you have</P>

<!-- CODE SNIP //-->

<PRE>

AddEncoding x-gzip gz

</PRE>

<!-- END CODE SNIP //-->

<P>and if you then access a file named myworld.wrl.gz, the MIME headers sent in response will look like the following (MIME headers of this format accompany every transfer over the Web; these headers are not displayed by the browser but are used to define how to handle the incoming file):

</P>

<!-- CODE SNIP //-->

<PRE>

Content-Type: x-world/x-vrml

Content-Encoding: x-gzip

</PRE>

<!-- END CODE SNIP //-->

<P>And any browser worth its salt will know, &#147;Oh, I have to decompress the file before handing it off to the VRML viewer.&#148;

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>With Apache 1.3, the optional module mod_mime_magic (if compiled in) can analyze the contents of a file and assign it a file type extension if one isn&#146;t present. This module is based on a free version of the UNIX file command.<HR></FONT>

</BLOCKQUOTE>

<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077"><I>Alias</I>, <I>ScriptAlias</I>, and <I>Redirect</I>

</FONT></H4>

<P>The <TT>Alias</TT>, <TT>ScriptAlias</TT>, and <TT>Redirect</TT> directives&#151;all denizens of srm.conf and all implemented by the mod_alias.c module&#151;allow you to have some flexibility with the mapping between <TT>URL-Space</TT> on your server and the actual layout of your file system.</P>

<P>Basically, any URL that looks like <A HREF="http://myhost.com/x/y/z">http://myhost.com/x/y/z</A> isn&#146;t required to map to a file named x/y/z under the document root of the server, acting much like a symbolic link. For example:</P>

<!-- CODE SNIP //-->

<PRE>

Alias <I>/path / /some/other/path/</I>

</PRE>

<!-- END CODE SNIP //-->

<P>The preceding directive takes a request for an object from the mythical subdirectory /<I>path</I> under the document root and maps it to another directory somewhere else entirely. For example, a request for</P>

<!-- CODE SNIP //-->

<PRE>

<A HREF="http://myhost.com/statistics/">http://myhost.com/statistics/</A>

</PRE>

<!-- END CODE SNIP //-->

<P>might normally go to document root /statistics, except that for whatever reason you wanted it to point somewhere outside the document root (for example, /usr/local/statistics). For that you&#146;d have to use the following command:

</P>

<!-- CODE SNIP //-->

<PRE>

Alias /statistics/ /usr/local/statistics/

</PRE>

<!-- END CODE SNIP //-->

<P>To the outside user, this would be completely transparent. If you use <TT>Alias</TT>, it&#146;s wise not to alias to somewhere else inside the document root. Furthermore, a request like</P>

<!-- CODE SNIP //-->

<PRE>

<A HREF="http://myhost.com/statistics/graph.gif">http://myhost.com/statistics/graph.gif</A>

</PRE>

<!-- END CODE SNIP //-->

<P>would get translated into a request for the file

</P>

<!-- CODE SNIP //-->

<PRE>

/usr/local/statistics/graph.gif

</PRE>

<!-- END CODE SNIP //-->

<P><TT>ScriptAlias</TT> is just like <TT>Alias</TT>, with the side effect of making everything in the subdirectory by default a CGI script. This might sound a bit bizarre, but the early model for building Web sites had all the CGI functionality separated into a directory by itself, and referenced through the Web server as shown in the following:</P>

<!-- CODE SNIP //-->

<PRE>

<A HREF="http://myhost.com/cgi-bin/script">http://myhost.com/cgi-bin/script</A>

</PRE>

<!-- END CODE SNIP //-->

<P>If you have in your srm.conf file

</P>

<!-- CODE SNIP //-->

<PRE>

ScriptAlias /cgi-bin/ /usr/local/etc/httpd/cgi-bin/

</PRE>

<!-- END CODE SNIP //-->

<P>then the preceding URL points to the script at /usr/local/etc/httpd/cgi-bin/script. As you&#146;ll see in a page or two, there&#146;s a more elegant way to specify that a file is a CGI script to be executed.

</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="683-686.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="688-690.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -