📄 697-699.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=697-699//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="695-697.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="699-702.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>For example, if you want to capture in your log just the remote host name, the object requested, and the timestamp, you would use the following:
</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "%h \"%r\" %t"
</PRE>
<!-- END CODE SNIP //-->
<P>And that would log things that looked like
</P>
<!-- CODE SNIP //-->
<PRE>
host.outsider.com "GET / HTTP/1.0" [06/Mar/1996:10:15:17]
</PRE>
<!-- END CODE SNIP //-->
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>You Can Quote Me on This</B></FONT>
<P>You really have to use quotation marks around the request variable. The configurable logging module will automatically interpret the values of the variables, rather than just read the variable name. Use a slash-quote, \”, to indicate that you want an actual quote character rather than the end of the string. For example, if you want to add logging of the <TT>User-Agent</TT> string, your log format would become</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "%h \"%r\" %t \"%{User-Agent}i\""
</PRE>
<!-- END CODE SNIP //-->
<P>Because the <TT>User-Agent</TT> field typically has spaces in it, it too should be quoted. Suppose that you want to capture the <TT>Referer</TT> field:</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "%h \"%r\" %t %{Referer}i"
</PRE>
<!-- END CODE SNIP //-->
<P>You don’t need the escaping quotation marks because <B>Referer</B> headers, as URLs, don’t have spaces in them. However, if you’re building a mission-critical application, you may as well quote it also, because the <B>Referer</B> header is supplied by the client and, thus, there are no guarantees about its format.</TABLE>
</P>
<P>The default logfile format is the Common Logfile Format (CLF), which is expressed as</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "%h %l %u %t \"%r\" %s %b"
</PRE>
<!-- END CODE SNIP //-->
<P>In fact, most existing logfile analysis tools for CLF will ignore extra fields tacked onto the end. To capture the most important extra information and yet still be parsable by those tools, you might want to use this format:
</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "%h %l %u %t \"%r\" %s %b %{Referer}i \"%{User-Agent}i\""
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>TIP: </B>If you want even more control over what gets logged, you can use the configurable logging module to implement a simple conditional test for variables. This way, you can configure it to log variables only when a particular status code is—or isn’t—returned. The format for trapping a status code is to insert a comma-separated list of those codes between the % and the letter of the variable:
<!-- CODE SNIP //-->
<PRE>
%404,403{Referer}i
</PRE>
<!-- END CODE SNIP //-->
<P>This example means that the <TT>Referer</TT> header will be logged only if the status returned by the server is a <TT>404 Not Found</TT> or a <TT>403 Access Denied</TT>. All other times just a <TT>-</TT> is logged. Having only 403 or 404 errors logged would be useful if all you cared about using <TT>Referer</TT> for was to find old links that point to resources no longer available.<HR></FONT>
</BLOCKQUOTE>
</P>
<P>The negation of the <TT>Referer</TT> status code is to put an exclamation point (!) at the beginning of the list of status codes. For example,</P>
<!-- CODE SNIP //-->
<PRE>
%!401u
</PRE>
<!-- END CODE SNIP //-->
<P>logs the user in any user authentication transaction, unless the authentication failed, in which case you probably don’t want to see the name of the bogus user anyway.
</P>
<P>Remember that, like many functions, logging functions can be configured per virtual host. Thus, if you want all logs from all virtual hosts on the same server to go to the same log, you might want to do something like</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "hosta ...."
</PRE>
<!-- END CODE SNIP //-->
<P>in the <TT><VirtualHost></TT> sections for hosta and</P>
<!-- CODE SNIP //-->
<PRE>
LogFormat "hostb ...."
</PRE>
<!-- END CODE SNIP //-->
<P>in the <TT><VirtualHost></TT> sections for hostb. More details about virtual hosts appear later in the section “Virtual Hosts.”</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>You have to compile in mod_log_config in order to configure logging on a “per-virtual-host” basis. You must also make sure that the default logging module, mod_log_common, isn’t compiled in; otherwise, the server will get confused.<HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Content Negotiation</FONT></H4>
<P><I>Content negotiation</I> is the mechanism by which a Web client can express to the server what data types it knows how to render and, based on that information, the server can give the client the “optimal” version of the resource requested. Content negotiation can happen on a number of different characteristics—the content type of the data (also called the <I>media type</I>), the human language the data is in (such as English or French), the character set of the document, and its encodings.</P>
<P><FONT SIZE="+1"><B>Content-Type Negotiation</B></FONT></P>
<P>If you want to use JPEG images inline on your pages but don’t want to alienate users with browsers that can’t handle inline JPEG images, you also can make a GIF version of that image. Although the GIF file might be larger or only 8-bit, that’s still better than giving the browser something it can’t handle, causing a broken link. So, the browser and the server <I>negotiate</I> for which data format the server sends to the client.</P>
<P>The specifications for content negotiation have been a part of HTTP since the beginning. Unfortunately, it can’t be relied on as extensively as you’d like. For example, current browsers that implement plug-ins by and large don’t express in the connection headers which media types they have plug-ins for. Thus, content negotiation currently can’t be used to decide whether to send someone a ShockWave file or its Java equivalent. The only safe place to use content negotiation now is to distinguish between inline JPEG or GIF images on a page. Enough browsers in use today implement content negotiation closely enough to get this functionality.</P>
<P>The mod_negotiation.c file in Apache 1.0 implements the content-negotiation specifications in an older version of the HTTP/1.0 IETF draft, which at this writing is on its way to RFC status. Content negotiation was removed because the specification wasn’t entirely complete. Content negotiation is getting significantly enhanced for HTTP/1.1. However, this doesn’t mean it can’t be safely used now for inline image selection.</P>
<P>To activate content negotiation, you must include the mod_negotiation.c module into the server. There are actually two ways to configure content negotiation:</P>
<DL>
<DD><B>•</B> Using a type-map file describing all the variants of a negotiable resource with specific preference values and content characteristics
<DD><B>•</B> Setting an <TT>Options</TT> value called <TT>MultiViews</TT>
</DL>
<P>Because your focus is pragmatic, you’ll go only into the <TT>MultiViews</TT> functionality. If you’re interested in the type-map functionality, the Apache Web site has documentation on it.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="695-697.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="699-702.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 + -