1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>Apache IP-based Virtual Host Support - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body id="manual-page"><div id="page-header"> 17<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 18<p class="apache">Apache HTTP Server Version 2.2</p> 19<img alt="" src="/images/feather.gif" /></div> 20<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 21<div id="path"> 22<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.2</a> > <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>Apache IP-based Virtual Host Support</h1> 23<div class="toplang"> 24<p><span>Available Languages: </span><a href="/en/vhosts/ip-based.html" title="English"> en </a> | 25<a href="/fr/vhosts/ip-based.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 26<a href="/ja/vhosts/ip-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 27<a href="/ko/vhosts/ip-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 28<a href="/tr/vhosts/ip-based.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 29</div> 30</div> 31<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#explanation">What is IP-based virtual hosting</a></li> 32<li><img alt="" src="/images/down.gif" /> <a href="#requirements">System requirements</a></li> 33<li><img alt="" src="/images/down.gif" /> <a href="#howto">How to set up Apache</a></li> 34<li><img alt="" src="/images/down.gif" /> <a href="#multiple">Setting up multiple daemons</a></li> 35<li><img alt="" src="/images/down.gif" /> <a href="#single">Setting up a single daemon 36 with virtual hosts</a></li> 37</ul><h3>See also</h3><ul class="seealso"><li> 38<a href="name-based.html">Name-based Virtual Hosts Support</a> 39</li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 40<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 41<div class="section"> 42<h2><a name="explanation" id="explanation">What is IP-based virtual hosting</a></h2> 43<p>IP-based virtual hosting is a method to apply different directives 44based on the IP address and port a request is received on. Most commonly, 45this is used to serve different websites on different ports or interfaces.</p> 46 47<p>In many cases, <a href="name-based.html">name-based 48virtual hosts</a> are more convenient, because they allow 49many virtual hosts to share a single address/port. 50See <a href="name-based.html#namevip">Name-based vs. IP-based 51Virtual Hosts</a> to help you decide. </p> 52</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 53<div class="section"> 54<h2><a name="requirements" id="requirements">System requirements</a></h2> 55 56 <p>As the term <cite>IP-based</cite> indicates, the server 57 <strong>must have a different IP address/port combination for each IP-based 58 virtual host</strong>. This can be achieved by the machine 59 having several physical network connections, or by use of 60 virtual interfaces which are supported by most modern operating 61 systems (see system documentation for details, these are 62 frequently called "ip aliases", and the "ifconfig" command is 63 most commonly used to set them up), and/or using multiple 64 port numbers.</p> 65 66 <p> In the terminology of Apache HTTP Server, using a single IP address 67 but multiple TCP ports, is also IP-based virtual hosting.</p> 68 69</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 70<div class="section"> 71<h2><a name="howto" id="howto">How to set up Apache</a></h2> 72 73 <p>There are two ways of configuring apache to support multiple 74 hosts. Either by running a separate <code class="program"><a href="/programs/httpd.html">httpd</a></code> daemon for 75 each hostname, or by running a single daemon which supports all the 76 virtual hosts.</p> 77 78 <p>Use multiple daemons when:</p> 79 80 <ul> 81 <li>There are security partitioning issues, such as company1 82 does not want anyone at company2 to be able to read their 83 data except via the web. In this case you would need two 84 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> 85 86 <li>You can afford the memory and file descriptor 87 requirements of listening to every IP alias on the 88 machine. It's only possible to <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> to the "wildcard" 89 address, or to specific addresses. So if you have a need to 90 listen to a specific address for whatever reason, then you 91 will need to listen to all specific addresses. (Although one 92 <code class="program"><a href="/programs/httpd.html">httpd</a></code> could listen to N-1 of the addresses, and another could 93 listen to the remaining address.)</li> 94 </ul> 95 96 <p>Use a single daemon when:</p> 97 98 <ul> 99 <li>Sharing of the httpd configuration between virtual hosts 100 is acceptable.</li> 101 102 <li>The machine services a large number of requests, and so 103 the performance loss in running separate daemons may be 104 significant.</li> 105 </ul> 106 107</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 108<div class="section"> 109<h2><a name="multiple" id="multiple">Setting up multiple daemons</a></h2> 110 111 <p>Create a separate <code class="program"><a href="/programs/httpd.html">httpd</a></code> installation for each 112 virtual host. For each installation, use the <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> directive in the 113 configuration file to select which IP address (or virtual host) 114 that daemon services. e.g.</p> 115 116 <div class="example"><p><code> 117 Listen 192.168.0.1:80 118 </code></p></div> 119 120 <p>It is recommended that you use an IP address instead of a 121 hostname (see <a href="/dns-caveats.html">DNS caveats</a>).</p> 122 123</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 124<div class="section"> 125<h2><a name="single" id="single">Setting up a single daemon 126 with virtual hosts</a></h2> 127 128 <p>For this case, a single <code class="program"><a href="/programs/httpd.html">httpd</a></code> will service 129 requests for the main server and all the virtual hosts. The <code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code> directive 130 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> 131 or <code class="directive"><a href="/mod/mod_log_config.html#customlog">CustomLog</a></code> 132 configuration directives to different values for each virtual 133 host. e.g.</p> 134 135 <div class="example"><p><code> 136 <VirtualHost 192.168.0.1:80><br /> 137 ServerAdmin webmaster@smallco.example.com<br /> 138 DocumentRoot /groups/smallco/www<br /> 139 ServerName smallco.example.com<br /> 140 ErrorLog /groups/smallco/logs/error_log<br /> 141 TransferLog /groups/smallco/logs/access_log<br /> 142 </VirtualHost><br /> 143 <br /> 144 <VirtualHost 192.168.0.2:80><br /> 145 ServerAdmin webmaster@baygroup.example.org<br /> 146 DocumentRoot /groups/baygroup/www<br /> 147 ServerName baygroup.example.com<br /> 148 ErrorLog /groups/baygroup/logs/error_log<br /> 149 TransferLog /groups/baygroup/logs/access_log<br /> 150</VirtualHost> 151 </code></p></div> 152 153 <p>It is recommended that you use an IP address instead of a 154 hostname in the <VirtualHost> directive 155 (see <a href="/dns-caveats.html">DNS caveats</a>).</p> 156 157 <p> Specific IP addresses or ports have precedence over their wildcard 158 equivalents, and any virtual host that matches has precedence over 159 the servers base configuration.</p> 160 161 <p>Almost <strong>any</strong> configuration directive can be 162 put in the VirtualHost directive, with the exception of 163 directives that control process creation and a few other 164 directives. To find out if a directive can be used in the 165 VirtualHost directive, check the <a href="/mod/directive-dict.html#Context">Context</a> using the 166 <a href="/mod/directives.html">directive index</a>.</p> 167 168 <p><code class="directive"><a href="/mod/mod_suexec.html#suexecusergroup">SuexecUserGroup</a></code> 169 may be used inside a 170 VirtualHost directive if the <a href="/suexec.html">suEXEC 171 wrapper</a> is used.</p> 172 173 <p><em>SECURITY:</em> When specifying where to write log files, 174 be aware of some security risks which are present if anyone 175 other than the user that starts Apache has write access to the 176 directory where they are written. See the <a href="/misc/security_tips.html">security tips</a> document 177 for details.</p> 178 179</div></div> 180<div class="bottomlang"> 181<p><span>Available Languages: </span><a href="/en/vhosts/ip-based.html" title="English"> en </a> | 182<a href="/fr/vhosts/ip-based.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> | 183<a href="/ja/vhosts/ip-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 184<a href="/ko/vhosts/ip-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 185<a href="/tr/vhosts/ip-based.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 186</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 187<script type="text/javascript"><!--//--><![CDATA[//><!-- 188var comments_shortname = 'httpd'; 189var comments_identifier = 'http://httpd.apache.org/docs/2.2/vhosts/ip-based.html'; 190(function(w, d) { 191 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 192 d.write('<div id="comments_thread"><\/div>'); 193 var s = d.createElement('script'); 194 s.type = 'text/javascript'; 195 s.async = true; 196 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 197 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 198 } 199 else { 200 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 201 } 202})(window, document); 203//--><!]]></script></div><div id="footer"> 204<p class="apache">Copyright 2013 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> 205<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 206if (typeof(prettyPrint) !== 'undefined') { 207 prettyPrint(); 208} 209//--><!]]></script> 210</body></html>