virtual-host.html revision 8a2af1684625dea5878341beffe18bbdf7bf4992
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
b5d34bc3082c1164ce20df48567d192e3e9f229fjim BGCOLOR="#FFFFFF"
b5d34bc3082c1164ce20df48567d192e3e9f229fjim TEXT="#000000"
b5d34bc3082c1164ce20df48567d192e3e9f229fjim LINK="#0000FF"
b5d34bc3082c1164ce20df48567d192e3e9f229fjim VLINK="#000080"
b5d34bc3082c1164ce20df48567d192e3e9f229fjim ALINK="#FF0000"
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<!--#include virtual="header.html" -->
2806775e45dfd5164d53fcb3d850d358f8ec2415jfclereThis is the ability of a single machine to be a web server for multiple
57a049796ba191c87b588cbde1323e8f65e3fea5jfcleredomains. For example, an Internet service provider might have a machine
b5d34bc3082c1164ce20df48567d192e3e9f229fjimcalled <code>www.serve.com</code> which provides Web space for several
a231b4cbdf1bd3d65dc13ead8d8a4f7e8b307314pquernaorganizations including, say, <em>smallco</em> and <em>baygroup</em>.
a231b4cbdf1bd3d65dc13ead8d8a4f7e8b307314pquernaOrdinarily, these groups would be given parts of the Web tree on www.serve.com.
a231b4cbdf1bd3d65dc13ead8d8a4f7e8b307314pquernaSo smallco's home page would have the URL
a231b4cbdf1bd3d65dc13ead8d8a4f7e8b307314pquerna<blockquote>
a231b4cbdf1bd3d65dc13ead8d8a4f7e8b307314pquerna</blockquote>
a231b4cbdf1bd3d65dc13ead8d8a4f7e8b307314pquernaand baygroup's home page would have the URL
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<blockquote>
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrin</blockquote>
4ab0fd1b54ce76f0fb6812b89b0b4dc7541014d6minfrinFor esthetic reasons, however, both organizations would rather their home
94b9a8750697ea0bf67a2a828e8034e5fe103ccatrawickpages appeared under their own names rather than that of the service
2806775e45dfd5164d53fcb3d850d358f8ec2415jfclereprovider's; but they do not want to set up their own Internet links and
2806775e45dfd5164d53fcb3d850d358f8ec2415jfclereVirtual hosts are the solution to this problem. smallco and baygroup would
2806775e45dfd5164d53fcb3d850d358f8ec2415jfclerehave their own Internet name registrations, <code>www.smallco.com</code> and
2806775e45dfd5164d53fcb3d850d358f8ec2415jfclere<code>www.baygroup.org</code> respectively. These hostnames would both
b5d34bc3082c1164ce20df48567d192e3e9f229fjimcorrespond to the service provider's machine (www.serve.com). Thus
b5d34bc3082c1164ce20df48567d192e3e9f229fjimsmallco's home page would now have the URL
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<blockquote>
b5d34bc3082c1164ce20df48567d192e3e9f229fjim</blockquote>
b5d34bc3082c1164ce20df48567d192e3e9f229fjimand baygroup's home page would would have the URL
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<blockquote>
b5d34bc3082c1164ce20df48567d192e3e9f229fjim</blockquote>
4c25fdfa5f370d29e55aea846eb9fe6c1d51ede3wroweDue to limitations in the HTTP/1.0 protocol, the web server <strong>must have a
b5d34bc3082c1164ce20df48567d192e3e9f229fjimdifferent IP address for each virtual host</strong>. This can be achieved
b5d34bc3082c1164ce20df48567d192e3e9f229fjimby the machine having several physical network connections, or by use
b5d34bc3082c1164ce20df48567d192e3e9f229fjimof a <a href="misc/vif-info.html">virtual interface</a> on some operating systems.
a515c3892232a3497bb58eeec5a1b9523571cf67jfclereThere are two ways of configuring apache to support multiple hosts.
a515c3892232a3497bb58eeec5a1b9523571cf67jfclereEither by running a separate httpd daemon for each hostname, or by running a
a515c3892232a3497bb58eeec5a1b9523571cf67jfcleresingle daemon which supports all the virtual hosts.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimUse multiple daemons when:
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>The different virtual hosts need very different httpd configurations, such
b5d34bc3082c1164ce20df48567d192e3e9f229fjim as different values for: <A HREF="mod/core.html#servertype">ServerType</A>,
b5d34bc3082c1164ce20df48567d192e3e9f229fjim <A HREF="mod/mod_mime.html#typesconfig">TypesConfig</A> or
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>The machine does not process a very high request rate.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimUse a single daemon when:
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>Sharing of the httpd configuration between virtual hosts is acceptable.
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>The machine services a large number of requests, and so the performance
b5d34bc3082c1164ce20df48567d192e3e9f229fjim loss in running separate daemons may be significant.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimCreate a separate httpd installation for each virtual host.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimFor each installation, use the
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<A HREF="mod/core.html#bindaddress">BindAddress</A> directive in the configuration
b5d34bc3082c1164ce20df48567d192e3e9f229fjimfile to select which IP address (or virtual host) that daemon services.
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<blockquote><code>BindAddress www.smallco.com</code></blockquote>
b5d34bc3082c1164ce20df48567d192e3e9f229fjimThis hostname can also be given as an IP address.
2806775e45dfd5164d53fcb3d850d358f8ec2415jfclereFor this case, a single httpd will service requests for all the virtual hosts.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimThe <A HREF="mod/core.html#virtualhost">VirtualHost</A> directive in the
b5d34bc3082c1164ce20df48567d192e3e9f229fjim configuration file is used to set the values of
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<A HREF="mod/mod_log_config.html#transferlog">TransferLog</A> configuration
b5d34bc3082c1164ce20df48567d192e3e9f229fjimdirectives to different values for each virtual host.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimServerAdmin webmaster@mail.smallco.com<br>
b5d34bc3082c1164ce20df48567d192e3e9f229fjim</VirtualHost><br>
b5d34bc3082c1164ce20df48567d192e3e9f229fjimServerAdmin webmaster@mail.baygroup.org<br>
b5d34bc3082c1164ce20df48567d192e3e9f229fjim</VirtualHost><br>
b5d34bc3082c1164ce20df48567d192e3e9f229fjimThis VirtualHost hostnames can also be given as IP addresses.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimAlmost <strong>ANY</strong> configuration directive can be put
b5d34bc3082c1164ce20df48567d192e3e9f229fjimin the VirtualHost directive, with the exception of
a84a6c5a1f176c4fc6ccbc1183dc7c9f401e18f1pquerna<A HREF="mod/core.html#maxspareservers">MaxSpareServers</A>,
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<A HREF="mod/core.html#minspareservers">MinSpareServers</A>,
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<A HREF="mod/core.html#maxrequestsperchild">MaxRequestsPerChild</A>,
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<A HREF="mod/mod_mime.html#typesconfig">TypesConfig</A>, and
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<EM>SECURITY:</EM> When specifying where to write log files, be aware
b5d34bc3082c1164ce20df48567d192e3e9f229fjimof some security risks which are present if anyone other than the
b5d34bc3082c1164ce20df48567d192e3e9f229fjimuser that starts Apache has write access to the directory where they
b5d34bc3082c1164ce20df48567d192e3e9f229fjimare written. See the <A HREF="misc/security_tips.html">security
b5d34bc3082c1164ce20df48567d192e3e9f229fjimtips</A> document for details.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimWhen using a large number of Virtual Hosts, Apache may run out of available
b5d34bc3082c1164ce20df48567d192e3e9f229fjimfile descriptors if each Virtual Host specifies different log files.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimThe total number of file descriptors used by Apache is one for each distinct
b5d34bc3082c1164ce20df48567d192e3e9f229fjimerror log file, one for every other log file directive, plus 10-20 for
b5d34bc3082c1164ce20df48567d192e3e9f229fjiminternal use. Unix operating systems limit the number of file descriptors that
b5d34bc3082c1164ce20df48567d192e3e9f229fjimmay be used by a process; the limit is typically 64, and may usually be
b5d34bc3082c1164ce20df48567d192e3e9f229fjimincreased up to a large hard-limit.
b5d34bc3082c1164ce20df48567d192e3e9f229fjimAlthough Apache attempts to increase the limit as required, this
b5d34bc3082c1164ce20df48567d192e3e9f229fjimmay not work if:
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>Your system does not provide the setrlimit() system call.
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>The setrlimit(RLIMIT_NOFILE) call does not function on your system
b5d34bc3082c1164ce20df48567d192e3e9f229fjim (such as Solaris 2.3)
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>The number of file descriptors required exceeds the hard limit.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim<li>Your system imposes other limits on file descriptors, such as a limit
a84a6c5a1f176c4fc6ccbc1183dc7c9f401e18f1pquernaon stdio streams only using file descriptors below 256. (Solaris 2)
b5d34bc3082c1164ce20df48567d192e3e9f229fjimIn the event of problems you can:
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>Reduce the number of log files; don't specify log files in the VirtualHost
b5d34bc3082c1164ce20df48567d192e3e9f229fjimsections, but only log to the main log files.
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<li>If you system falls into 1 or 2 (above), then increase the file descriptor
c87ed6a25f669f7137024ccde3771d95b9c37e07jfclerelimit before starting Apache, using a script like
b5d34bc3082c1164ce20df48567d192e3e9f229fjimulimit -S -n 100 <br>
b5d34bc3082c1164ce20df48567d192e3e9f229fjimThe have been reports that Apache may start running out of resources allocated
b5d34bc3082c1164ce20df48567d192e3e9f229fjimfor the root process. This will exhibit itself as errors in the error log like
b5d34bc3082c1164ce20df48567d192e3e9f229fjim"unable to fork". There are two ways you can bump this up:
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<LI>Have a <code>csh</code> script wrapper around httpd which sets the
b5d34bc3082c1164ce20df48567d192e3e9f229fjim"rlimit" to some large number, like 512.
b5d34bc3082c1164ce20df48567d192e3e9f229fjim<LI>Edit http_main.c to add calls to setrlimit() from main(), along the lines of
b5d34bc3082c1164ce20df48567d192e3e9f229fjim struct rlimit rlp;
b5d34bc3082c1164ce20df48567d192e3e9f229fjim if (setrlimit(RLIMIT_NPROC, &rlp)) {
b5d34bc3082c1164ce20df48567d192e3e9f229fjim fprintf(stderr, "setrlimit(RLIMIT_NPROC) failed.\n");
c87ed6a25f669f7137024ccde3771d95b9c37e07jfclere(thanks to "Aaron Gifford <agifford@InfoWest.COM>" for the patch)
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jimThe latter will probably manifest itself in a later version of Apache.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim<!--#include virtual="footer.html" -->