virtual-host.html revision f9b3be308809978f797e0c57b296147532a4313c
af84459fbf938e508fd10b01cb8d699c79083813takashi<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
af84459fbf938e508fd10b01cb8d699c79083813takashi<HTML>
af84459fbf938e508fd10b01cb8d699c79083813takashi<HEAD>
af84459fbf938e508fd10b01cb8d699c79083813takashi<TITLE>Apache Server Virtual Host Support</TITLE>
af84459fbf938e508fd10b01cb8d699c79083813takashi</HEAD>
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
af84459fbf938e508fd10b01cb8d699c79083813takashi<BODY
af84459fbf938e508fd10b01cb8d699c79083813takashi BGCOLOR="#FFFFFF"
af84459fbf938e508fd10b01cb8d699c79083813takashi TEXT="#000000"
af84459fbf938e508fd10b01cb8d699c79083813takashi LINK="#0000FF"
af84459fbf938e508fd10b01cb8d699c79083813takashi VLINK="#000080"
af84459fbf938e508fd10b01cb8d699c79083813takashi ALINK="#FF0000"
af84459fbf938e508fd10b01cb8d699c79083813takashi>
af84459fbf938e508fd10b01cb8d699c79083813takashi<!--#include virtual="header.html" -->
af84459fbf938e508fd10b01cb8d699c79083813takashi<h1 ALIGN="CENTER">Virtual Host Support</H1>
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi<STRONG>See Also:</STRONG>
af84459fbf938e508fd10b01cb8d699c79083813takashi<A HREF="host.html">Non-IP based virtual hosts</A>
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi<h2>What are virtual hosts?</h2>
af84459fbf938e508fd10b01cb8d699c79083813takashiThis is the ability of a single machine to be a web server for multiple
af84459fbf938e508fd10b01cb8d699c79083813takashidomains. For example, an Internet service provider might have a machine
af84459fbf938e508fd10b01cb8d699c79083813takashicalled <CODE>www.serve.com</CODE> which provides Web space for several
af84459fbf938e508fd10b01cb8d699c79083813takashiorganizations including, say, <EM>smallco</EM> and <EM>baygroup</EM>.
af84459fbf938e508fd10b01cb8d699c79083813takashiOrdinarily, these groups would be given parts of the Web tree on www.serve.com.
af84459fbf938e508fd10b01cb8d699c79083813takashiSo smallco's home page would have the URL
af84459fbf938e508fd10b01cb8d699c79083813takashi<BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashihttp://www.serve.com/smallco/
af84459fbf938e508fd10b01cb8d699c79083813takashi</BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashiand baygroup's home page would have the URL
af84459fbf938e508fd10b01cb8d699c79083813takashi<BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashihttp://www.serve.com/baygroup/
af84459fbf938e508fd10b01cb8d699c79083813takashi</BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashi<P>
af84459fbf938e508fd10b01cb8d699c79083813takashiFor esthetic reasons, however, both organizations would rather their home
af84459fbf938e508fd10b01cb8d699c79083813takashipages appeared under their own names rather than that of the service
af84459fbf938e508fd10b01cb8d699c79083813takashiprovider's; but they do not want to set up their own Internet links and
af84459fbf938e508fd10b01cb8d699c79083813takashiservers.
50cb7e2b30597f481fee57bac945190f06ebcc58jorton<P>
50cb7e2b30597f481fee57bac945190f06ebcc58jortonVirtual hosts are the solution to this problem. smallco and baygroup would
50cb7e2b30597f481fee57bac945190f06ebcc58jortonhave their own Internet name registrations, <CODE>www.smallco.com</CODE> and
50cb7e2b30597f481fee57bac945190f06ebcc58jorton<CODE>www.baygroup.org</CODE> respectively. These hostnames would both
50cb7e2b30597f481fee57bac945190f06ebcc58jortoncorrespond to the service provider's machine (www.serve.com). Thus
50cb7e2b30597f481fee57bac945190f06ebcc58jortonsmallco's home page would now have the URL
50cb7e2b30597f481fee57bac945190f06ebcc58jorton<BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashihttp://www.smallco.com/
af84459fbf938e508fd10b01cb8d699c79083813takashi</BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashiand baygroup's home page would would have the URL
af84459fbf938e508fd10b01cb8d699c79083813takashi<BLOCKQUOTE>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunhttp://www.baygroup.org/
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun</BLOCKQUOTE>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<h2>System requirements</h2>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunDue to limitations in the HTTP/1.0 protocol, the web server <STRONG>must have a
c04f76acce77126cf88b09350e56ea8c6b4a064enilgundifferent IP address for each virtual host</STRONG>. This can be achieved
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunby the machine having several physical network connections, or by use
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunof a <A HREF="misc/vif-info.html">virtual interface</A> on some operating systems.
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<h2>How to set up Apache</h2>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunThere are two ways of configuring apache to support multiple hosts.
af84459fbf938e508fd10b01cb8d699c79083813takashiEither by running a separate httpd daemon for each hostname, or by running a
af84459fbf938e508fd10b01cb8d699c79083813takashisingle daemon which supports all the virtual hosts.
af84459fbf938e508fd10b01cb8d699c79083813takashi<P>
af84459fbf938e508fd10b01cb8d699c79083813takashiUse multiple daemons when:
af84459fbf938e508fd10b01cb8d699c79083813takashi<UL>
af84459fbf938e508fd10b01cb8d699c79083813takashi<LI>The different virtual hosts need very different httpd configurations, such
af84459fbf938e508fd10b01cb8d699c79083813takashi as different values for: <A HREF="mod/core.html#servertype">ServerType</A>,
af84459fbf938e508fd10b01cb8d699c79083813takashi <A HREF="mod/core.html#user">User</A>,
af84459fbf938e508fd10b01cb8d699c79083813takashi <A HREF="mod/core.html#group">Group</A>,
af84459fbf938e508fd10b01cb8d699c79083813takashi <A HREF="mod/mod_mime.html#typesconfig">TypesConfig</A> or
af84459fbf938e508fd10b01cb8d699c79083813takashi <A HREF="mod/core.html#serverroot">ServerRoot</A>.
af84459fbf938e508fd10b01cb8d699c79083813takashi<LI>The machine does not process a very high request rate.
af84459fbf938e508fd10b01cb8d699c79083813takashi</UL>
af84459fbf938e508fd10b01cb8d699c79083813takashiUse a single daemon when:
af84459fbf938e508fd10b01cb8d699c79083813takashi<UL>
af84459fbf938e508fd10b01cb8d699c79083813takashi<LI>Sharing of the httpd configuration between virtual hosts is acceptable.
af84459fbf938e508fd10b01cb8d699c79083813takashi<LI>The machine services a large number of requests, and so the performance
af84459fbf938e508fd10b01cb8d699c79083813takashi loss in running separate daemons may be significant.
af84459fbf938e508fd10b01cb8d699c79083813takashi</UL>
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi<h2>Setting up multiple daemons</h2>
af84459fbf938e508fd10b01cb8d699c79083813takashiCreate a separate httpd installation for each virtual host.
af84459fbf938e508fd10b01cb8d699c79083813takashiFor each installation, use the
d0828c8a321dc5e9ea60550f052294669c08cf93jim<A HREF="mod/core.html#bindaddress">BindAddress</A> directive in the configuration
af84459fbf938e508fd10b01cb8d699c79083813takashifile to select which IP address (or virtual host) that daemon services.
af84459fbf938e508fd10b01cb8d699c79083813takashie.g.
af84459fbf938e508fd10b01cb8d699c79083813takashi<BLOCKQUOTE><CODE>BindAddress www.smallco.com</CODE></BLOCKQUOTE>
af84459fbf938e508fd10b01cb8d699c79083813takashiThis hostname can also be given as an IP address.
d0828c8a321dc5e9ea60550f052294669c08cf93jim
cd6c8de3bedcc401ee230159b0439fa20f44488etakashi<h2>Setting up a single daemon</h2>
cd6c8de3bedcc401ee230159b0439fa20f44488etakashiFor this case, a single httpd will service requests for all the virtual hosts.
d0828c8a321dc5e9ea60550f052294669c08cf93jimThe <A HREF="mod/core.html#virtualhost">VirtualHost</A> directive in the
d0828c8a321dc5e9ea60550f052294669c08cf93jim configuration file is used to set the values of
cd6c8de3bedcc401ee230159b0439fa20f44488etakashi<A HREF="mod/core.html#serveradmin">ServerAdmin</A>,
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<A HREF="mod/core.html#servername">ServerName</A>,
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<A HREF="mod/core.html#documentroot">DocumentRoot</A>,
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<A HREF="mod/core.html#errorlog">ErrorLog</A> and
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<A HREF="mod/mod_log_config.html#transferlog">TransferLog</A> configuration
c04f76acce77126cf88b09350e56ea8c6b4a064enilgundirectives to different values for each virtual host.
c04f76acce77126cf88b09350e56ea8c6b4a064enilgune.g.
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun<BLOCKQUOTE><CODE>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgun&lt;VirtualHost www.smallco.com&gt;<BR>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunServerAdmin webmaster@mail.smallco.com<BR>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunDocumentRoot /groups/smallco/www<BR>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunServerName www.smallco.com<BR>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunErrorLog /groups/smallco/logs/error_log<BR>
c04f76acce77126cf88b09350e56ea8c6b4a064enilgunTransferLog /groups/smallco/logs/access_log<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashi&lt;/VirtualHost&gt;<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashi<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashi&lt;VirtualHost www.baygroup.org&gt;<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashiServerAdmin webmaster@mail.baygroup.org<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashiDocumentRoot /groups/baygroup/www<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashiServerName www.baygroup.org<BR>
b036ef2952fb6924b308f954b39786443460ddc6rpluemErrorLog /groups/baygroup/logs/error_log<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashiTransferLog /groups/baygroup/logs/access_log<BR>
af84459fbf938e508fd10b01cb8d699c79083813takashi&lt;/VirtualHost&gt;<BR>
</CODE></BLOCKQUOTE>
This VirtualHost hostnames can also be given as IP addresses.
<P>
Almost <STRONG>ANY</STRONG> configuration directive can be put
in the VirtualHost directive, with the exception of
<A HREF="mod/core.html#servertype">ServerType</A>,
<A HREF="mod/core.html#user">User</A>,
<A HREF="mod/core.html#group">Group</A>,
<A HREF="mod/core.html#startservers">StartServers</A>,
<A HREF="mod/core.html#maxspareservers">MaxSpareServers</A>,
<A HREF="mod/core.html#minspareservers">MinSpareServers</A>,
<A HREF="mod/core.html#maxrequestsperchild">MaxRequestsPerChild</A>,
<A HREF="mod/core.html#bindaddress">BindAddress</A>,
<A HREF="mod/core.html#pidfile">PidFile</A>,
<A HREF="mod/mod_mime.html#typesconfig">TypesConfig</A>, and
<A HREF="mod/core.html#serverroot">ServerRoot</A>.
<P>
<EM>SECURITY:</EM> When specifying where to write log files, be aware
of some security risks which are present if anyone other than the
user that starts Apache has write access to the directory where they
are written. See the <A HREF="misc/security_tips.html">security
tips</A> document for details.
<P>
<H2>File Handle/Resource Limits:</H2>
When using a large number of Virtual Hosts, Apache may run out of available
file descriptors if each Virtual Host specifies different log files.
The total number of file descriptors used by Apache is one for each distinct
error log file, one for every other log file directive, plus 10-20 for
internal use. Unix operating systems limit the number of file descriptors that
may be used by a process; the limit is typically 64, and may usually be
increased up to a large hard-limit.
<P>
Although Apache attempts to increase the limit as required, this
may not work if:
<OL>
<LI>Your system does not provide the setrlimit() system call.
<LI>The setrlimit(RLIMIT_NOFILE) call does not function on your system
(such as Solaris 2.3)
<LI>The number of file descriptors required exceeds the hard limit.
<LI>Your system imposes other limits on file descriptors, such as a limit
on stdio streams only using file descriptors below 256. (Solaris 2)
</OL>
In the event of problems you can:
<UL>
<LI>Reduce the number of log files; don't specify log files in the VirtualHost
sections, but only log to the main log files.
<LI>If you system falls into 1 or 2 (above), then increase the file descriptor
limit before starting Apache, using a script like
<BLOCKQUOTE><CODE>
#!/bin/sh <BR>
ulimit -S -n 100 <BR>
exec httpd</CODE></BLOCKQUOTE>
</UL>
The have been reports that Apache may start running out of resources allocated
for the root process. This will exhibit itself as errors in the error log like
"unable to fork". There are two ways you can bump this up:
<OL>
<LI>Have a <CODE>csh</CODE> script wrapper around httpd which sets the
"rlimit" to some large number, like 512.
<LI>Edit http_main.c to add calls to setrlimit() from main(), along the lines of
<PRE>
struct rlimit rlp;
rlp.rlim_cur = rlp.rlim_max = 512;
if (setrlimit(RLIMIT_NPROC, &rlp)) {
fprintf(stderr, "setrlimit(RLIMIT_NPROC) failed.\n");
exit(1);
}
</PRE>
(thanks to "Aaron Gifford &lt;agifford@InfoWest.COM&gt;" for the patch)
</OL>
The latter will probably manifest itself in a later version of Apache.
<!--#include virtual="footer.html" -->
</BODY></HTML>