ip-based.html.en revision 3f08db06526d6901aa08c110b5bc7dde6bc39905
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<?xml version="1.0" encoding="ISO-8859-1"?>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd This file is generated from xml source: DO NOT EDIT
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd -->
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<title>Apache IP-based Virtual Host Support - Apache HTTP Server</title>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<body id="manual-page"><div id="page-header">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p class="apache">Apache HTTP Server Version 2.5</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<img alt="" src="/images/feather.gif" /></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div id="path">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>Apache IP-based Virtual Host Support</h1>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="toplang">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p><span>Available Languages: </span><a href="/en/vhosts/ip-based.html" title="English">&nbsp;en&nbsp;</a> |
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<a href="/fr/vhosts/ip-based.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<a href="/ja/vhosts/ip-based.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<a href="/ko/vhosts/ip-based.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<a href="/tr/vhosts/ip-based.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#explanation">What is IP-based virtual hosting</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#requirements">System requirements</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#howto">How to set up Apache</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#multiple">Setting up multiple daemons</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<li><img alt="" src="/images/down.gif" /> <a href="#single">Setting up a single daemon
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd with virtual hosts</a></li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</ul><h3>See also</h3><ul class="seealso"><li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<a href="name-based.html">Name-based Virtual Hosts Support</a>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</li></ul></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="section">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<h2><a name="explanation" id="explanation">What is IP-based virtual hosting</a></h2>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p>IP-based virtual hosting is a method to apply different directives
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndbased on the IP address and port a request is received on. Most commonly,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndthis is used to serve different websites on different ports or interfaces.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<p>In many cases, <a href="name-based.html">name-based
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndvirtual hosts</a> are more convenient, because they allow
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndmany virtual hosts to share a single address/port.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndSee <a href="name-based.html#namevip">Name-based vs. IP-based
6116c12fdd3ed06d388fe6572e50a22e9320dfa5ndVirtual Hosts</a> to help you decide. </p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="section">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<h2><a name="requirements" id="requirements">System requirements</a></h2>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>As the term <cite>IP-based</cite> indicates, the server
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <strong>must have a different IP address/port combination for each IP-based
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd virtual host</strong>. This can be achieved by the machine
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd having several physical network connections, or by use of
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd virtual interfaces which are supported by most modern operating
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd systems (see system documentation for details, these are
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd frequently called "ip aliases", and the "ifconfig" command is
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd most commonly used to set them up), and/or using multiple
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd port numbers.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p> In the terminology of Apache HTTP Server, using a single IP address
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd but multiple TCP ports, is also IP-based virtual hosting.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<div class="section">
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd<h2><a name="howto" id="howto">How to set up Apache</a></h2>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>There are two ways of configuring apache to support multiple
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd hosts. Either by running a separate <code class="program"><a href="/programs/httpd.html">httpd</a></code> daemon for
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd each hostname, or by running a single daemon which supports all the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd virtual hosts.</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <p>Use multiple daemons when:</p>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <ul>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <li>There are security partitioning issues, such as company1
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd does not want anyone at company2 to be able to read their
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd data except via the web. In this case you would need two
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd daemons, each running with different <code class="directive"><a href="/mod/mpm_common.html#user">User</a></code>, <code class="directive"><a href="/mod/mpm_common.html#group">Group</a></code>, <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code>, and <code class="directive"><a href="/mod/core.html#serverroot">ServerRoot</a></code> settings.</li>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <li>You can afford the memory and file descriptor
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd requirements of listening to every IP alias on the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd machine. It's only possible to <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> to the "wildcard"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd address, or to specific addresses. So if you have a need to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd listen to a specific address for whatever reason, then you
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd will need to listen to all specific addresses. (Although one
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <code class="program"><a href="/programs/httpd.html">httpd</a></code> could listen to N-1 of the addresses, and another could
listen to the remaining address.)</li>
</ul>
<p>Use a single daemon when:</p>
<ul>
<li>Sharing of the httpd configuration between virtual hosts
is acceptable.</li>
<li>The machine services a large number of requests, and so
the performance loss in running separate daemons may be
significant.</li>
</ul>
</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="section">
<h2><a name="multiple" id="multiple">Setting up multiple daemons</a></h2>
<p>Create a separate <code class="program"><a href="/programs/httpd.html">httpd</a></code> installation for each
virtual host. For each installation, use the <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> directive in the
configuration file to select which IP address (or virtual host)
that daemon services. e.g.</p>
<div class="example"><p><code>
Listen 192.0.2.100:80
</code></p></div>
<p>It is recommended that you use an IP address instead of a
hostname (see <a href="/dns-caveats.html">DNS caveats</a>).</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
<div class="section">
<h2><a name="single" id="single">Setting up a single daemon
with virtual hosts</a></h2>
<p>For this case, a single <code class="program"><a href="/programs/httpd.html">httpd</a></code> will service
requests for the main server and all the virtual hosts. The <code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code> directive
in the configuration file is used to set the values of <code class="directive"><a href="/mod/core.html#serveradmin">ServerAdmin</a></code>, <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code>, <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>, <code class="directive"><a href="/mod/core.html#errorlog">ErrorLog</a></code> and <code class="directive"><a href="/mod/mod_log_config.html#transferlog">TransferLog</a></code>
or <code class="directive"><a href="/mod/mod_log_config.html#customlog">CustomLog</a></code>
configuration directives to different values for each virtual
host. e.g.</p>
<div class="example"><p><code>
&lt;VirtualHost 172.20.30.40:80&gt;<br />
ServerAdmin webmaster@www1.example.com<br />
DocumentRoot /www/vhosts/www1<br />
ServerName www1.example.com<br />
ErrorLog /www/logs/www1/error_log<br />
CustomLog /www/logs/www1/access_log combined<br />
&lt;/VirtualHost&gt;<br />
<br />
&lt;VirtualHost 172.20.30.50:80&gt;<br />
ServerAdmin webmaster@www2.example.org<br />
DocumentRoot /www/vhosts/www2<br />
ServerName www2.example.org<br />
ErrorLog /www/logs/www2/error_log<br />
CustomLog /www/logs/www2/access_log combined<br />
&lt;/VirtualHost&gt;
</code></p></div>
<p>It is recommended that you use an IP address instead of a
hostname in the &lt;VirtualHost&gt; directive
(see <a href="/dns-caveats.html">DNS caveats</a>).</p>
<p> Specific IP addresses or ports have precedence over their wildcard
equivalents, and any virtual host that matches has precedence over
the servers base configuration.</p>
<p>Almost <strong>any</strong> configuration directive can be
put in the VirtualHost directive, with the exception of
directives that control process creation and a few other
directives. To find out if a directive can be used in the
VirtualHost directive, check the <a href="/mod/directive-dict.html#Context">Context</a> using the
<a href="/mod/directives.html">directive index</a>.</p>
<p><code class="directive"><a href="/mod/mod_suexec.html#suexecusergroup">SuexecUserGroup</a></code>
may be used inside a
VirtualHost directive if the <a href="/suexec.html">suEXEC
wrapper</a> is used.</p>
<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>
</div></div>
<div class="bottomlang">
<p><span>Available Languages: </span><a href="/en/vhosts/ip-based.html" title="English">&nbsp;en&nbsp;</a> |
<a href="/fr/vhosts/ip-based.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
<a href="/ja/vhosts/ip-based.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
<a href="/ko/vhosts/ip-based.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
<a href="/tr/vhosts/ip-based.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
</div><div id="footer">
<p class="apache">Copyright 2011 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>
</body></html>