📄 705-707.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=705-707//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="702-705.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="707-708.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">Database Management File Authentication</FONT></H4>
<P>You also can configure Apache to use DBM files for faster password and group-membership lookups. To use a DBM file, you must have the mod_auth_dbm module compiled into the server.
</P>
<P>DBM files are UNIX file types that implement a fast hash table lookup, making them ideal for handling large user/password databases. The flat-file systems require parsing the password file for every access until a match is found, potentially going through the entire file before returning a “can’t find that user” error. Hash tables, on the other hand, know instantly whether a “key” exists in the database and what its value is.</P>
<P>Some systems use the ndbm libraries; some use the berkeley db libraries. However, the interface through Apache is exactly the same.</P>
<P>To use a DBM file for the database rather than a regular flat file, you use a different directive—<TT>AuthDBMUserFile</TT>—instead of <TT>AuthUserFile</TT>. Likewise, for the group file, <TT>AuthDBMGroupFile</TT> is used instead of <TT>AuthGroupFile</TT>.</P>
<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Virtual Hosts</FONT></H4>
<P>Apache implements a very clean way of handling <I>virtual hosts</I>, which is the mechanism for being able to serve more than one host on a particular machine. Due to a limitation in HTTP, serving multiple hosts is now accomplished by assigning more than one IP number to a machine and then having Apache bind differently to those different IP numbers. For example, a UNIX box might have 204.122.133.1, 204.122.133.2, and 204.122.133.3 pointing to it, with <A HREF="www.host1.com">www.host1.com</A> bound to the first, <A HREF="www.host2.com">www.host2.com</A> bound to the second, and <A HREF="www.host3.com">www.host3.com</A> bound to the third.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>TIP: </B>Apache 1.2 and above, via the HTTP 1.1 protocol specification, supports non-IP based virtual hosts as well. With this new feature, you no longer have to provide an IP address for each virtual host.<HR></FONT>
</BLOCKQUOTE>
<P>Virtual hosts are configured by using a container in httpd.conf. They look something like this:
</P>
<!-- CODE SNIP //-->
<PRE>
<VirtualHost www.host1.com>
DocumentRoot /www/htdocs/host1/
TransferLog logs/access.host1
ErrorLog logs/error.host1
</VirtualHost>
</PRE>
<!-- END CODE SNIP //-->
<P>The attribute in the <TT>VirtualHost</TT> tag is the host name, which the server looks up to get an IP address.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>If there’s any chance that <A HREF="www.host1.com">www.host1.com</A> can return more than one number or that the Web server might have trouble resolving the host name to an IP number at any point, you might want to use the IP number instead.<HR></FONT>
</BLOCKQUOTE>
<P>Any directives put within the <TT>VirtualHost</TT> container pertain only to requests made to that host name. <TT>DocumentRoot</TT> points to a directory that presumably contains content specifically for <A HREF="www.host1.com">www.host1.com</A>.</P>
<P>Each virtual host can have its own access log, its own error log, its own derivative of the other logs out there, its own <TT>Redirect</TT> and <TT>Alias</TT> directives, its own <TT>ServerName</TT> and <TT>ServerAdmin</TT> directives, and more. In fact, the only things a virtual host server can’t support out of the core set of directives are</P>
<CENTER>
<TABLE WIDTH="88%"><TR>
<TD WIDTH="50%"><TT>ServerType</TT>
<TD WIDTH="50%"><TT>MaxRequestsPerChild</TT>
<TR>
<TD><TT>UserId</TT>
<TD><TT>BindAddress</TT>
<TR>
<TD><TT>GroupId</TT>
<TD><TT>PidFile</TT>
<TR>
<TD><TT>StartServers</TT>
<TD><TT>TypesConfig</TT>
<TR>
<TD><TT>MaxSpareServers</TT>
<TD><TT>ServerRoot</TT>
<TR>
<TD><TT>MinSpareServers</TT>
<TD>
</TABLE>
</CENTER>
<P>If you plan to run Apache with a large number of virtual hosts, you need to be careful to watch the process limits. For example, some UNIX platforms allow processes to open only 64 file descriptors at once. Because an Apache child will consume one file descriptor per logfile per virtual host, 32 virtual hosts—each with its own transfer and error log—would quickly cross that process limit. You’ll notice when you’re running into problems of this kind if your error logs start reporting such errors as <TT>unable to fork()</TT>, or your access logs aren’t getting written to at all. Apache does try to call <TT>setrlimit()</TT> (a system function call to try to limit processes) to handle this problem on its own, but the system sometimes prevents it from making the system call successfully.</P>
<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Customized Error Messages</FONT></H4>
<P>Apache can give customized responses in the event of an error. This is controlled by using the <TT>ErrorDocument</TT> directive. The syntax is as follows:</P>
<!-- CODE SNIP //-->
<PRE>
ErrorDocument <I>HTTP_response_code action</I>
</PRE>
<!-- END CODE SNIP //-->
<P><TT><I>HTTP_response_code</I></TT> is the event that triggers the <I>action</I>. The <I>action</I> can be</P>
<DL>
<DD><B>•</B> A local URI to which the server is internally redirected
<DD><B>•</B> An external URL to which the client is redirected
<DD><B>•</B> A text string that starts with a " character and where the <TT>%s</TT> variable contains any extra information, if available
</DL>
<P>For example,
</P>
<!-- CODE SNIP //-->
<PRE>
ErrorDocument 500 "Ack! We have a problem here: %s.
ErrorDocument 500 /errors/500.cgi
ErrorDocument 500 http://backup.myhost.com/
ErrorDocument 401 /subscribe.html
ErrorDocument 404 /debug/record-broken-links.cgi
</PRE>
<!-- END CODE SNIP //-->
<P>Two extra CGI variables are passed to any redirected resource: <TT>REDIRECT_URL</TT> contains the original URL requested, and <TT>REDIRECT_STATUS</TT> gives the original status that caused the redirection. This will help the script if its job is to try to figure out what caused the error response.</P>
<H4 ALIGN="LEFT"><A NAME="Heading21"></A><FONT COLOR="#000077">Assorted httpd.conf Settings</FONT></H4>
<P>A few additional configuration options just don’t fit in anywhere else, because their functionality is a bit unique or different. These options include <TT>BindAddress</TT>, <TT>PidFile</TT>, and <TT>Timeout</TT>.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="702-705.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="707-708.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 + -