ip-based.html.en revision ac082aefa89416cbdc9a1836eaf3bed9698201c8
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess This file is generated from xml source: DO NOT EDIT
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5a58787efeb02a1c3f06569d019ad81fd2efa06end<title>Apache IP-based Virtual Host Support - Apache HTTP Server</title>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<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" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<script src="/style/scripts/prettify.js" type="text/javascript">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/images/favicon.ico" rel="shortcut icon" /></head>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<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>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<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.5</a> > <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>Apache IP-based Virtual Host Support</h1>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/vhosts/ip-based.html" title="English"> en </a> |
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd<a href="/fr/vhosts/ip-based.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd<a href="/ja/vhosts/ip-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi<a href="/ko/vhosts/ip-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<a href="/tr/vhosts/ip-based.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#explanation">What is IP-based virtual hosting</a></li>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf<li><img alt="" src="/images/down.gif" /> <a href="#requirements">System requirements</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#howto">How to set up Apache</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#multiple">Setting up multiple daemons</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#single">Setting up a single daemon
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<a href="name-based.html">Name-based Virtual Hosts Support</a>
5a58787efeb02a1c3f06569d019ad81fd2efa06end</li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf<h2><a name="explanation" id="explanation">What is IP-based virtual hosting</a></h2>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf<p>IP-based virtual hosting is a method to apply different directives
6e14faf37935e36804b8bad802bc9dd58f3cf65dsfbased on the IP address and port a request is received on. Most commonly,
6e14faf37935e36804b8bad802bc9dd58f3cf65dsfthis is used to serve different websites on different ports or interfaces.</p>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsfvirtual hosts</a> are more convenient, because they allow
6e14faf37935e36804b8bad802bc9dd58f3cf65dsfSee <a href="name-based.html#namevip">Name-based vs. IP-based
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="requirements" id="requirements">System requirements</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>As the term <cite>IP-based</cite> indicates, the server
60a4b2c422dcbb08a554fb193105c08da592718bpoirier <strong>must have a different IP address/port combination for each IP-based
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess virtual host</strong>. This can be achieved by the machine
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess having several physical network connections, or by use of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess virtual interfaces which are supported by most modern operating
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess systems (see system documentation for details, these are
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess frequently called "ip aliases", and the "ifconfig" command is
60a4b2c422dcbb08a554fb193105c08da592718bpoirier most commonly used to set them up), and/or using multiple
60a4b2c422dcbb08a554fb193105c08da592718bpoirier port numbers.</p>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <p> In the terminology of Apache HTTP Server, using a single IP address
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf but multiple TCP ports, is also IP-based virtual hosting.</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="howto" id="howto">How to set up Apache</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>There are two ways of configuring apache to support multiple
9bcfc3697a91b5215893a7d0206865b13fc72148nd hosts. Either by running a separate <code class="program"><a href="/programs/httpd.html">httpd</a></code> daemon for
9bcfc3697a91b5215893a7d0206865b13fc72148nd each hostname, or by running a single daemon which supports all the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess virtual hosts.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>There are security partitioning issues, such as company1
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess does not want anyone at company2 to be able to read their
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess data except via the web. In this case you would need two
df47c169dad27600c1e98e547a065378c5e9a2b3rbowen daemons, each running with different <code class="directive"><a href="/mod/mod_unixd.html#user">User</a></code>, <code class="directive"><a href="/mod/mod_unixd.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>
cd9f05dfac570b44f26f531e01869e679c45401berikabele <li>You can afford the memory and file descriptor
cd9f05dfac570b44f26f531e01869e679c45401berikabele requirements of listening to every IP alias on the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess machine. It's only possible to <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> to the "wildcard"
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess address, or to specific addresses. So if you have a need to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess listen to a specific address for whatever reason, then you
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess will need to listen to all specific addresses. (Although one
9bcfc3697a91b5215893a7d0206865b13fc72148nd <code class="program"><a href="/programs/httpd.html">httpd</a></code> could listen to N-1 of the addresses, and another could
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess listen to the remaining address.)</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>Sharing of the httpd configuration between virtual hosts
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess is acceptable.</li>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <li>The machine services a large number of requests, and so
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the performance loss in running separate daemons may be
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess significant.</li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="multiple" id="multiple">Setting up multiple daemons</a></h2>
9bcfc3697a91b5215893a7d0206865b13fc72148nd <p>Create a separate <code class="program"><a href="/programs/httpd.html">httpd</a></code> installation for each
9bcfc3697a91b5215893a7d0206865b13fc72148nd virtual host. For each installation, use the <code class="directive"><a href="/mod/mpm_common.html#listen">Listen</a></code> directive in the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration file to select which IP address (or virtual host)
76d83a94f9ceb90468ea20abc98622e489afef9fcovener Listen 192.0.2.100:80
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>It is recommended that you use an IP address instead of a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess hostname (see <a href="/dns-caveats.html">DNS caveats</a>).</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="single" id="single">Setting up a single daemon
9bcfc3697a91b5215893a7d0206865b13fc72148nd <p>For this case, a single <code class="program"><a href="/programs/httpd.html">httpd</a></code> will service
9bcfc3697a91b5215893a7d0206865b13fc72148nd requests for the main server and all the virtual hosts. The <code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code> directive
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess 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>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess or <code class="directive"><a href="/mod/mod_log_config.html#customlog">CustomLog</a></code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess configuration directives to different values for each virtual
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen<VirtualHost 172.20.30.40:80>
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerAdmin webmaster@www1.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen</VirtualHost>
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen<VirtualHost 172.20.30.50:80>
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerAdmin webmaster@www2.example.org
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen</VirtualHost>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>It is recommended that you use an IP address instead of a
fc0e302cc26d443c3441238f00e7b5a201b3bbb9rbowen hostname in the <VirtualHost> directive
fc0e302cc26d443c3441238f00e7b5a201b3bbb9rbowen (see <a href="/dns-caveats.html">DNS caveats</a>).</p>
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <p> Specific IP addresses or ports have precedence over their wildcard
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf equivalents, and any virtual host that matches has precedence over
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf the servers base configuration.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Almost <strong>any</strong> configuration directive can be
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess put in the VirtualHost directive, with the exception of
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directives that control process creation and a few other
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directives. To find out if a directive can be used in the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess VirtualHost directive, check the <a href="/mod/directive-dict.html#Context">Context</a> using the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <a href="/mod/directives.html">directive index</a>.</p>
1f6b6946407b900ccef68a0e9cd8baa0eba429e8rbowen <p><code class="directive"><a href="/mod/mod_suexec.html#suexecusergroup">SuexecUserGroup</a></code>
1f6b6946407b900ccef68a0e9cd8baa0eba429e8rbowen may be used inside a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess VirtualHost directive if the <a href="/suexec.html">suEXEC
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p><em>SECURITY:</em> When specifying where to write log files,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess be aware of some security risks which are present if anyone
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess other than the user that starts Apache has write access to the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directory where they are written. See the <a href="/misc/security_tips.html">security tips</a> document
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for details.</p>
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/vhosts/ip-based.html" title="English"> en </a> |
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd<a href="/fr/vhosts/ip-based.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd<a href="/ja/vhosts/ip-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi<a href="/ko/vhosts/ip-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<a href="/tr/vhosts/ip-based.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</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>
5effc8b39fae5cd169d17f342bfc265705840014rbowen<script type="text/javascript"><!--//--><![CDATA[//><!--
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowenvar comments_shortname = 'httpd';
2c9e74eac9f72c14535dd65a520e4de2e664d9cdhumbedoohvar comments_identifier = 'http://httpd.apache.org/docs/trunk/vhosts/ip-based.html';
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen(function(w, d) {
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen d.write('<div id="comments_thread"><\/div>');
5a58787efeb02a1c3f06569d019ad81fd2efa06end var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
<p class="apache">Copyright 2012 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="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[//><!--