examples.html.en revision 3f08db06526d6901aa08c110b5bc7dde6bc39905
beaad6ac31022179c44d88536811e9ccd9425696nd<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
beaad6ac31022179c44d88536811e9ccd9425696nd<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
6fbd2e53c97ea6976d93e0ac521adabc55e0fb73nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
beaad6ac31022179c44d88536811e9ccd9425696nd This file is generated from xml source: DO NOT EDIT
beaad6ac31022179c44d88536811e9ccd9425696nd XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
beaad6ac31022179c44d88536811e9ccd9425696nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
beaad6ac31022179c44d88536811e9ccd9425696nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
beaad6ac31022179c44d88536811e9ccd9425696nd<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
beaad6ac31022179c44d88536811e9ccd9425696nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
beaad6ac31022179c44d88536811e9ccd9425696nd<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>
beaad6ac31022179c44d88536811e9ccd9425696nd<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
01c674544bd4c211141bcd9fb09b96ffc18c6c3dnd<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>VirtualHost Examples</h1>
01c674544bd4c211141bcd9fb09b96ffc18c6c3dnd<p><span>Available Languages: </span><a href="/en/vhosts/examples.html" title="English"> en </a> |
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<a href="/fr/vhosts/examples.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<a href="/ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<a href="/ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<a href="/tr/vhosts/examples.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <p>This document attempts to answer the commonly-asked questions about
7e68fce3cbd2246164e045a51ecd77f9f26680ednd setting up <a href="index.html">virtual hosts</a>. These scenarios are those involving multiple
66e48875fca2df6669dab4f2690ee36c6913c0ffnd web sites running on a single server, via <a href="name-based.html">name-based</a> or <a href="ip-based.html">IP-based</a> virtual hosts.
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#purename">Running several name-based web
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<li><img alt="" src="/images/down.gif" /> <a href="#twoips">Name-based hosts on more than one
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<li><img alt="" src="/images/down.gif" /> <a href="#intraextra">Serving the same content on
7e68fce3cbd2246164e045a51ecd77f9f26680ednd different IP addresses (such as an internal and external
a8571599bf3a6921cc0b9f609009e4ec1f59e1d0nd<li><img alt="" src="/images/down.gif" /> <a href="#port">Running different sites on different
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<li><img alt="" src="/images/down.gif" /> <a href="#ip">IP-based virtual hosting</a></li>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<li><img alt="" src="/images/down.gif" /> <a href="#ipport">Mixed port-based and ip-based virtual
a8571599bf3a6921cc0b9f609009e4ec1f59e1d0nd<li><img alt="" src="/images/down.gif" /> <a href="#mixed">Mixed name-based and IP-based
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<li><img alt="" src="/images/down.gif" /> <a href="#proxy">Using <code>Virtual_host</code> and
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<li><img alt="" src="/images/down.gif" /> <a href="#default">Using <code>_default_</code>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<li><img alt="" src="/images/down.gif" /> <a href="#migrate">Migrating a name-based vhost to an
8cfbcde8e416fd60132dd4324c42a5098da156cfnd<li><img alt="" src="/images/down.gif" /> <a href="#serverpath">Using the <code>ServerPath</code>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd<h2><a name="purename" id="purename">Running several name-based web
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <p>Your server has a single IP address, and multiple aliases (CNAMES)
7e68fce3cbd2246164e045a51ecd77f9f26680ednd point to this machine in DNS. You want to run a web server for
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <code>www.example.com</code> and <code>www.example.org</code> on this
d3cd98e7839dd1c737c18d42a916ed20860a50e1nd machine.</p>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd host configurations on your Apache server does not magically
7e68fce3cbd2246164e045a51ecd77f9f26680ednd cause DNS entries to be created for those host names. You
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <em>must</em> have the names in DNS, resolving to your IP
7e68fce3cbd2246164e045a51ecd77f9f26680ednd address, or nobody else will be able to see your web site. You
7e68fce3cbd2246164e045a51ecd77f9f26680ednd can put entries in your <code>hosts</code> file for local
7e68fce3cbd2246164e045a51ecd77f9f26680ednd testing, but that will work only from the machine with those
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <div class="example"><h3>Server configuration</h3><p><code>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd # Ensure that Apache listens on port 80<br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd Listen 80<br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <VirtualHost *:80><br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd # Other directives here<br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd </VirtualHost><br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <VirtualHost *:80><br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd # Other directives here<br />
7e68fce3cbd2246164e045a51ecd77f9f26680ednd </VirtualHost>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <p>The asterisks match all addresses, so the main server serves no
7e68fce3cbd2246164e045a51ecd77f9f26680ednd requests. Due to the fact that the virtual host with
7e68fce3cbd2246164e045a51ecd77f9f26680ednd in the configuration file, it has the highest priority and can be seen
7e68fce3cbd2246164e045a51ecd77f9f26680ednd as the <cite>default</cite> or <cite>primary</cite> server. That means
7e68fce3cbd2246164e045a51ecd77f9f26680ednd that if a request is received that does not match one of the specified
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <code>ServerName</code> directives, it will be served by this first
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <p>You can, if you wish, replace <code>*</code> with the actual
7e68fce3cbd2246164e045a51ecd77f9f26680ednd IP address of the system, when you don't care to discriminate based
7e68fce3cbd2246164e045a51ecd77f9f26680ednd on the IP address or port.</p>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <p>However, it is additionally useful to use <code>*</code>
7e68fce3cbd2246164e045a51ecd77f9f26680ednd on systems where the IP address is not predictable - for
7e68fce3cbd2246164e045a51ecd77f9f26680ednd example if you have a dynamic IP address with your ISP, and
7e68fce3cbd2246164e045a51ecd77f9f26680ednd you are using some variety of dynamic DNS solution. Since
7e68fce3cbd2246164e045a51ecd77f9f26680ednd <code>*</code> matches any IP address, this configuration
7e68fce3cbd2246164e045a51ecd77f9f26680ednd would work without changes whenever your IP address
3726777f47ac4bba3e21b075905959bbea47e72eerikabele changes.</p>
at <code>192.168.111.2</code>. The <code class="directive"><a href="/mod/mod_proxy.html#proxypreservehost on">ProxyPreserveHost On</a></code> directive is
<p>You can use <code class="directive"><a href="/mod/mod_alias.html#aliasmatch">AliasMatch</a></code> or
<code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to rewrite any
<code>www.example.org</code> (from our <a href="#name">name-based</a> example, setup 2) should get its own IP
<p>The <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directives
<p><span>Available Languages: </span><a href="/en/vhosts/examples.html" title="English"> en </a> |
<a href="/fr/vhosts/examples.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
<a href="/ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="/ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
<a href="/tr/vhosts/examples.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
<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>