SlideShare a Scribd company logo
VirtualHost Examples - Apache HTTP Server                                                                            Page 1




                             Apache HTTP Server Version 2.2
                                            VirtualHost Examples
       This document attempts to answer the commonly   -asked questions about setting up virtual hosts. These scenarios
       are those involving multiple web sites running on a single server, via name-based ( name-based.html) or IP-
       based ( ip-based.html) virtual hosts.


         Running several name-based web sites on a single IP address.
         Name-based hosts on more than one IP address.
         Serving the same content on different IP addresses (such as an internal and external address).
         Running different sites on different ports.
         IP-based virtual hosting
         Mixed port-based and ip-based virtual hosts
         Mixed name-based and IP-based vhosts
         Using Virtual_host and mod_proxy together
         Using _default_ vhosts
         Migrating a name-based vhost to an IP-based vhost
         Using the ServerPath directive

       Running several name-based web sites on a single IP address.
       Your server has a single IP address, and multiple aliases (CNAMES) point to this machine in DNS. You want
       to run a web server for www.example.com and www.example.org on this machine.

           Note
          Creating virtual host configurations on your Apache server does not magically cause DNS entries to be
          created for those host names. You must have the names in DNS, resolving to your IP address, or
          nobody else will be able to see your web site. You can put entries in your hosts file for local testing,
          but that will work only from the machine with those hosts entries.


           Server configuration
          # Ensure that Apache listens on port 80
          Listen 80

          # Listen for virtual host requests on all IP addresses
          NameVirtualHost *:80

          <VirtualHost *:80>
             DocumentRoot /www/example 1
             ServerName www.example .com

              # Other directives here

          </VirtualHost >

          <VirtualHost *:80>
             DocumentRoot /www/example 2
             ServerName www.example .org

              # Other directives here

          </VirtualHost >


       The asterisks match all addresses, so the main server serves no requests. Due to the fact that
       www.example.com is first in the configuration file, it has the highest priority and can be seen as the default




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                                24/12/2007 00:38:16
VirtualHost Examples - Apache HTTP Server                                                                                  Page 2



       or primary server. That means that if a request is received that does not match one of the specified
       ServerName directives, it will be served by this first VirtualHost.

           Note
           You can, if you wish, replace * with the actual IP address of the system. In that case, the argument to
           VirtualHost must match the argument to NameVirtualHost:

               NameVirtualHost 172.20.30.40

               <VirtualHost 172.20.30.40>
               # etc ...


           However, it is additionally useful to use * on systems where the IP address is not predictable - for
           example if you have a dynamic IP address with your ISP, and you are using some variety of dynamic
           DNS solution. Since * matches any IP address, this configuration would work without changes
           whenever your IP address changes.

       The above configuration is what you will want to use in almost all name-based virtual hosting situations. The
       only thing that this configuration will not work for, in fact, is when you are serving different content based on
       differing IP addresses or ports.

       Name-based hosts on more than one IP address.

           Note
           Any of the techniques discussed here can be extended to any number of IP addresses.

       The server has two IP addresses. On one (172.20.30.40), we will serve the "main" server,
       server.domain.com and on the other (172.20.30.50), we will serve two or more virtual hosts.

           Server configuration
           Listen 80

           # This is the "main" server running on 172.20.30.40
           ServerName server.domain.com
           DocumentRoot /www/mainserver

           # This is the other address
           NameVirtualHost 172.20.30.50

           <VirtualHost 172.20.30.50>
              DocumentRoot /www/example 1
              ServerName www.example .com

              # Other directives here ...

           </VirtualHost >

           <VirtualHost 172.20.30.50>
              DocumentRoot /www/example 2
              ServerName www.example .org

              # Other directives here ...

           </VirtualHost >


       Any request to an address other than 172.20.30.50 will be served from the main server. A request to
       172.20.30.50 with an unknown hostname, or no Host: header, will be served from
       www.example.com.




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                                   24/12/2007 00:38:16
VirtualHost Examples - Apache HTTP Server                                                                            Page 3




       Serving the same content on different IP addresses (such as
       an internal and external address).
       The server machine has two IP addresses (192.168.1.1 and 172.20.30.40). The machine is sitting
       between an internal (intranet) network and an external (internet) network. Outside of the network, the name
       server.example.com resolves to the external address (172.20.30.40), but inside the network, that
       same name resolves to the internal address (192.168.1.1).

       The server can be made to respond to internal and external requests with the same content, with just one
       VirtualHost section.

           Server configuration
          NameVirtualHost 192.168.1.1
          NameVirtualHost 172.20.30.40

          <VirtualHost 192.168.1.1 172.20.30.40>
             DocumentRoot /www/server1
             ServerName server.example .com
             ServerAlias server
          </VirtualHost >


       Now requests from both networks will be served from the same VirtualHost.

           Note:
          On the internal network, one can just use the name server rather than the fully qualified host name
          server.example.com.
          Note also that, in the above example, you can replace the list of IP addresses with *, which will cause
          the server to respond the same on all addresses.


       Running different sites on different ports.
       You have multiple domains going to the same IP and also want to serve multiple ports. By defining the ports in
       the "NameVirtualHost" tag, you can allow this to work. If you try using <VirtualHost name:port> without the
       NameVirtualHost name:port or you try to use the Listen directive, your configuration will not work.

           Server configuration
          Listen 80
          Listen 8080

          NameVirtualHost 172.20.30.40:80
          NameVirtualHost 172.20.30.40:8080

          <VirtualHost 172.20.30.40:80>
             ServerName www.example .com
             DocumentRoot /www/domain-80
          </VirtualHost >

          <VirtualHost 172.20.30.40:8080>
             ServerName www.example .com
             DocumentRoot /www/domain-8080
          </VirtualHost >

          <VirtualHost 172.20.30.40:80>
             ServerName www.example .org
             DocumentRoot /www/otherdomain -80
          </VirtualHost >

          <VirtualHost 172.20.30.40:8080>
             ServerName www.example .org
             DocumentRoot /www/otherdomain -8080




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                                24/12/2007 00:38:16
VirtualHost Examples - Apache HTTP Server                                                                      Page 4



          </VirtualHost >


       IP-based virtual hosting
       The server has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the names
       www.example.com and www.example.org respectively.

           Server configuration
          Listen 80

          <VirtualHost 172.20.30.40>
             DocumentRoot /www/example 1
             ServerName www.example .com
          </VirtualHost >

          <VirtualHost 172.20.30.50>
             DocumentRoot /www/example 2
             ServerName www.example .org
          </VirtualHost >


       Requests for any address not specified in one of the <VirtualHost> directives (such as localhost, for
       example) will go to the main server, if there is one.

       Mixed port-based and ip-based virtual hosts
       The server machine has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the
       names www.example.com and www.example.org respectively. In each case, we want to run hosts on
       ports 80 and 8080.

           Server configuration
          Listen   172.20.30.40:80
          Listen   172.20.30.40:8080
          Listen   172.20.30.50:80
          Listen   172.20.30.50:8080

          <VirtualHost 172.20.30.40:80>
             DocumentRoot /www/example 1-80
             ServerName www.example .com
          </VirtualHost >

          <VirtualHost 172.20.30.40:8080>
             DocumentRoot /www/example 1-8080
             ServerName www.example .com
          </VirtualHost >

          <VirtualHost 172.20.30.50:80>
             DocumentRoot /www/example 2-80
             ServerName www.example .org
          </VirtualHost >

          <VirtualHost 172.20.30.50:8080>
             DocumentRoot /www/example 2-8080
             ServerName www.example .org
          </VirtualHost >


       Mixed name-based and IP-based vhosts
       On some of my addresses, I want to do name-based virtual hosts, and on others, IP-based hosts.

           Server configuration




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                              24/12/2007 00:38:16
VirtualHost Examples - Apache HTTP Server                                                                              Page 5



           Listen 80

           NameVirtualHost 172.20.30.40

           <VirtualHost 172.20.30.40>
              DocumentRoot /www/example 1
              ServerName www.example .com
           </VirtualHost >

           <VirtualHost 172.20.30.40>
              DocumentRoot /www/example 2
              ServerName www.example .org
           </VirtualHost >

           <VirtualHost 172.20.30.40>
              DocumentRoot /www/example 3
              ServerName www.example 3.net
           </VirtualHost >

           # IP-based
           <VirtualHost 172.20.30.50>
              DocumentRoot /www/example 4
              ServerName www.example 4.edu
           </VirtualHost >

           <VirtualHost 172.20.30.60>
              DocumentRoot /www/example 5
              ServerName www.example 5.gov
           </VirtualHost >


       Using Virtual_host and mod_proxy together
       The following example allows a front-end machine to proxy a virtual host through to a server running on
       another machine. In the example, a virtual host of the same name is configured on a machine at
       192.168.111.2. The ProxyPreserveHost On directive is used so that the desired hostname is passed
       through, in case we are proxying multiple hostnames to a single machine.

           <VirtualHost *:*>
           ProxyPreserveHost On
           ProxyPass / http://192.168.111.2
           ProxyPassReverse / http://192.168.111.2/
           ServerName hostname .example .com
           </VirtualHost >


       Using _default_ vhosts

       _default_ vhosts for all ports
       Catching every request to any unspecified IP address and port, i.e. , an address/port combination that is not
       used for any other virtual host.

           Server configuration
           <VirtualHost _default _:*>
              DocumentRoot /www/default
           </VirtualHost >


       Using such a default vhost with a wildcard port effectively prevents any request going to the main server.

       A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If
       the request contained an unknown or no Host: header it is always served from the primary name-based vhost
       (the vhost for that address/port appearing first in the configuration file).




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                                  24/12/2007 00:38:16
VirtualHost Examples - Apache HTTP Server                                                                             Page 6



       You can use AliasMatch or RewriteRule to rewrite any request to a single information page (or script).

       _default_ vhosts for different ports
       Same as setup 1, but the server listens on several ports and we want to use a second _default_ vhost for
       port 80.

           Server configuration
          <VirtualHost _default _:80>
             DocumentRoot /www/default 80
             # ...
          </VirtualHost >

          <VirtualHost _default _:*>
             DocumentRoot /www/default
             # ...
          </VirtualHost >


       The default vhost for port 80 (which must appear before any default vhost with a wildcard port) catches all
       requests that were sent to an unspecified IP address. The main server is never used to serve a request.

       _default_ vhosts for one port
       We want to have a default vhost for port 80, but no other default vhosts.

           Server configuration
          <VirtualHost _default _:80>
          DocumentRoot /www/default
          ...
          </VirtualHost >


       A request to an unspecified address on port 80 is served from the default vhost. Any other request to an
       unspecified address and port is served from the main server.

       Migrating a name-based vhost to an IP-based vhost
       The name-based vhost with the hostname www.example.org (from our name-based ( #name) example,
       setup 2) should get its own IP address. To avoid problems with name servers or proxies who cached the old IP
       address for the name-based vhost we want to provide both variants during a migration phase.

       The solution is easy, because we can simply add the new IP address (172.20.30.50) to the
       VirtualHost directive.

           Server configuration
          Listen 80
          ServerName www.example .com
          DocumentRoot /www/example 1

          NameVirtualHost 172.20.30.40

          <VirtualHost 172.20.30.40 172.20.30.50>
             DocumentRoot /www/example 2
             ServerName www.example .org
             # ...
          </VirtualHost >

          <VirtualHost 172.20.30.40>
             DocumentRoot /www/example 3
             ServerName www.example .net
             ServerAlias *.example .net
             # ...




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                                24/12/2007 00:38:16
VirtualHost Examples - Apache HTTP Server                                                                           Page 7



          </VirtualHost >


       The vhost can now be accessed through the new address (as an IP-based vhost) and through the old address (as
       a name-based vhost).

       Using the ServerPath directive
       We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the
       correct Host: header. Old HTTP/1.0 clients do not send such a header and Apache has no clue what vhost the
       client tried to reach (and serves the request from the primary vhost). To provide as much backward
       compatibility as possible we create a primary vhost which returns a single page containing links with an URL
       prefix to the name-based virtual hosts.

           Server configuration
          NameVirtualHost 172.20.30.40

          <VirtualHost 172.20.30.40>
             # primary vhost
             DocumentRoot /www/subdomain
             RewriteEngine On
             RewriteRule ^/.* /www/subdomain/index.html
             # ...
          </VirtualHost >

          <VirtualHost 172.20.30.40>
          DocumentRoot /www/subdomain/sub1
             ServerName www.sub1.domain.tld
             ServerPath /sub1/
             RewriteEngine On
             RewriteRule ^(/sub1/.*) /www/subdomain$1
             # ...
          </VirtualHost >

          <VirtualHost 172.20.30.40>
             DocumentRoot /www/subdomain/sub2
             ServerName www.sub2.domain.tld
             ServerPath /sub2/
             RewriteEngine On
             RewriteRule ^(/sub2/.*) /www/subdomain$1
             # ...
          </VirtualHost >


       Due to the ServerPath directive a request to the URL http://www.sub1.domain.tld/sub1/ is
       always served from the sub1-vhost.
       A request to the URL http://www.sub1.domain.tld/ is only served from the sub1-vhost if the client
       sent a correct Host: header. If no Host: header is sent the client gets the information page from the primary
       host.

       Please note that there is one oddity: A request to http://www.sub2.domain.tld/sub1/ is also served
       from the sub1-vhost if the client sent no Host: header.

       The RewriteRule directives are used to make sure that a client which sent a correct Host: header can use
       both URL variants, i.e. , with or without URL prefix.

                                   Copyright 2007 The Apache Software Foundation.
                                   Licensed under the Apache License, Version 2.0.




http://httpd.apache.org/docs/2.2/vhosts/examples.html                                               24/12/2007 00:38:16

More Related Content

What's hot

Apache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual HostingApache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual Hosting
webhostingguy
 
Apache Web Server Setup 4
Apache Web Server Setup 4Apache Web Server Setup 4
Apache Web Server Setup 4
Information Technology
 
Ajax
AjaxAjax
Apache Web Server Setup 1
Apache Web Server Setup 1Apache Web Server Setup 1
Apache Web Server Setup 1
Information Technology
 
Apache
ApacheApache
Apache
NIRMAL FELIX
 
Apache Web Server Setup 3
Apache Web Server Setup 3Apache Web Server Setup 3
Apache Web Server Setup 3
Information Technology
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
webhostingguy
 
Linux Webserver Installation Command and GUI.ppt
Linux Webserver Installation Command and GUI.pptLinux Webserver Installation Command and GUI.ppt
Linux Webserver Installation Command and GUI.ppt
webhostingguy
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
Joseph Scott
 
Nginx cheat sheet
Nginx cheat sheetNginx cheat sheet
Nginx cheat sheet
Lam Hoang
 
Apache
ApacheApache
Apache
Rathan Raj
 
Get more than a cache back! - ConFoo Montreal
Get more than a cache back! - ConFoo MontrealGet more than a cache back! - ConFoo Montreal
Get more than a cache back! - ConFoo Montreal
Maarten Balliauw
 
Apache ppt
Apache pptApache ppt
Apache ppt
Sanmuga Nathan
 
Css
CssCss
Apache Presentation
Apache PresentationApache Presentation
Apache Presentation
Ankush Jain
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011
Rich Bowen
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010
Rich Bowen
 
Apache Ppt
Apache PptApache Ppt
Apache Ppt
Hema Prasanth
 
Lightweight DAS components in Perl
Lightweight DAS components in PerlLightweight DAS components in Perl
Lightweight DAS components in Perl
guestbab097
 
Apache Server Tutorial
Apache Server TutorialApache Server Tutorial
Apache Server Tutorial
Jagat Kothari
 

What's hot (20)

Apache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual HostingApache web server installation/configuration, Virtual Hosting
Apache web server installation/configuration, Virtual Hosting
 
Apache Web Server Setup 4
Apache Web Server Setup 4Apache Web Server Setup 4
Apache Web Server Setup 4
 
Ajax
AjaxAjax
Ajax
 
Apache Web Server Setup 1
Apache Web Server Setup 1Apache Web Server Setup 1
Apache Web Server Setup 1
 
Apache
ApacheApache
Apache
 
Apache Web Server Setup 3
Apache Web Server Setup 3Apache Web Server Setup 3
Apache Web Server Setup 3
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
 
Linux Webserver Installation Command and GUI.ppt
Linux Webserver Installation Command and GUI.pptLinux Webserver Installation Command and GUI.ppt
Linux Webserver Installation Command and GUI.ppt
 
Site Performance - From Pinto to Ferrari
Site Performance - From Pinto to FerrariSite Performance - From Pinto to Ferrari
Site Performance - From Pinto to Ferrari
 
Nginx cheat sheet
Nginx cheat sheetNginx cheat sheet
Nginx cheat sheet
 
Apache
ApacheApache
Apache
 
Get more than a cache back! - ConFoo Montreal
Get more than a cache back! - ConFoo MontrealGet more than a cache back! - ConFoo Montreal
Get more than a cache back! - ConFoo Montreal
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Css
CssCss
Css
 
Apache Presentation
Apache PresentationApache Presentation
Apache Presentation
 
Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011Apache Wizardry - Ohio Linux 2011
Apache Wizardry - Ohio Linux 2011
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010
 
Apache Ppt
Apache PptApache Ppt
Apache Ppt
 
Lightweight DAS components in Perl
Lightweight DAS components in PerlLightweight DAS components in Perl
Lightweight DAS components in Perl
 
Apache Server Tutorial
Apache Server TutorialApache Server Tutorial
Apache Server Tutorial
 

Viewers also liked

Tutorial virtual host dan ssl
Tutorial virtual host dan sslTutorial virtual host dan ssl
Tutorial virtual host dan ssl
ANDRI HAIRIYADI, S.Kom.
 
Names and virtual host discovery
Names and virtual host discoveryNames and virtual host discovery
Names and virtual host discovery
jekil
 
Virtual Server Presentation Dha
Virtual Server Presentation DhaVirtual Server Presentation Dha
Virtual Server Presentation Dha
mcshinsky
 
Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
webhostingguy
 
Resume
ResumeResume
Satyanarayan 5+Years Exp WAS Admin
Satyanarayan 5+Years Exp WAS AdminSatyanarayan 5+Years Exp WAS Admin
Satyanarayan 5+Years Exp WAS Admin
Satya (mca)
 
Dns
DnsDns

Viewers also liked (7)

Tutorial virtual host dan ssl
Tutorial virtual host dan sslTutorial virtual host dan ssl
Tutorial virtual host dan ssl
 
Names and virtual host discovery
Names and virtual host discoveryNames and virtual host discovery
Names and virtual host discovery
 
Virtual Server Presentation Dha
Virtual Server Presentation DhaVirtual Server Presentation Dha
Virtual Server Presentation Dha
 
Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
 
Resume
ResumeResume
Resume
 
Satyanarayan 5+Years Exp WAS Admin
Satyanarayan 5+Years Exp WAS AdminSatyanarayan 5+Years Exp WAS Admin
Satyanarayan 5+Years Exp WAS Admin
 
Dns
DnsDns
Dns
 

Similar to Virtual host examples_-_apache_http_server

Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
webhostingguy
 
Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
webhostingguy
 
Linux System Administration - Web Server and squid setup
Linux System Administration - Web Server and squid setupLinux System Administration - Web Server and squid setup
Linux System Administration - Web Server and squid setup
Sreenatha Reddy K R
 
Apache server configuration & optimization
Apache server configuration & optimizationApache server configuration & optimization
Apache server configuration & optimization
Gokul Muralidharan
 
are available here
are available hereare available here
are available here
webhostingguy
 
Http
HttpHttp
Apache
ApacheApache
Apache
Raghu nath
 
Virtual Hosts Configuration with Weblogic Server
Virtual Hosts Configuration with Weblogic ServerVirtual Hosts Configuration with Weblogic Server
Virtual Hosts Configuration with Weblogic Server
Pawan Kumar
 
Web servers
Web serversWeb servers
Web servers
webhostingguy
 
Web server
Web serverWeb server
Web server
MOHSIN HASAN
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
webhostingguy
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011
Alfred Ayache
 
Virtual Hosting With Apache and Linux
Virtual Hosting With Apache and LinuxVirtual Hosting With Apache and Linux
Virtual Hosting With Apache and Linux
Iresha Rubasinghe
 
APACHE 2 HTTPS.ppt
APACHE 2 HTTPS.pptAPACHE 2 HTTPS.ppt
APACHE 2 HTTPS.ppt
webhostingguy
 
Apache1.ppt
Apache1.pptApache1.ppt
Apache1.ppt
webhostingguy
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
webhostingguy
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
Ortus Solutions, Corp
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
webhostingguy
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
webhostingguy
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
webhostingguy
 

Similar to Virtual host examples_-_apache_http_server (20)

Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
 
Web Server Administration
Web Server AdministrationWeb Server Administration
Web Server Administration
 
Linux System Administration - Web Server and squid setup
Linux System Administration - Web Server and squid setupLinux System Administration - Web Server and squid setup
Linux System Administration - Web Server and squid setup
 
Apache server configuration & optimization
Apache server configuration & optimizationApache server configuration & optimization
Apache server configuration & optimization
 
are available here
are available hereare available here
are available here
 
Http
HttpHttp
Http
 
Apache
ApacheApache
Apache
 
Virtual Hosts Configuration with Weblogic Server
Virtual Hosts Configuration with Weblogic ServerVirtual Hosts Configuration with Weblogic Server
Virtual Hosts Configuration with Weblogic Server
 
Web servers
Web serversWeb servers
Web servers
 
Web server
Web serverWeb server
Web server
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
 
WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011WP Sandbox Presentation WordCamp Toronto 2011
WP Sandbox Presentation WordCamp Toronto 2011
 
Virtual Hosting With Apache and Linux
Virtual Hosting With Apache and LinuxVirtual Hosting With Apache and Linux
Virtual Hosting With Apache and Linux
 
APACHE 2 HTTPS.ppt
APACHE 2 HTTPS.pptAPACHE 2 HTTPS.ppt
APACHE 2 HTTPS.ppt
 
Apache1.ppt
Apache1.pptApache1.ppt
Apache1.ppt
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
 

More from HARRY CHAN PUTRA

07 VLAN Principle and Configuration.pdf
07 VLAN Principle and Configuration.pdf07 VLAN Principle and Configuration.pdf
07 VLAN Principle and Configuration.pdf
HARRY CHAN PUTRA
 
12 link aggregation configuration
12 link aggregation configuration12 link aggregation configuration
12 link aggregation configuration
HARRY CHAN PUTRA
 
11 mac address table characteristic configuration
11 mac address table characteristic configuration11 mac address table characteristic configuration
11 mac address table characteristic configuration
HARRY CHAN PUTRA
 
05 interface appended characteristic configuration
05 interface appended characteristic configuration05 interface appended characteristic configuration
05 interface appended characteristic configuration
HARRY CHAN PUTRA
 
Bdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manualBdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manual
HARRY CHAN PUTRA
 
Mplsvpn seminar
Mplsvpn seminarMplsvpn seminar
Mplsvpn seminar
HARRY CHAN PUTRA
 
Firewall ip filter
Firewall ip filterFirewall ip filter
Firewall ip filter
HARRY CHAN PUTRA
 
Zxdsl 9210 guide
Zxdsl 9210 guideZxdsl 9210 guide
Zxdsl 9210 guide
HARRY CHAN PUTRA
 
9210 commissioning manual
9210 commissioning manual9210 commissioning manual
9210 commissioning manual
HARRY CHAN PUTRA
 
Bsd routers
Bsd routersBsd routers
Bsd routers
HARRY CHAN PUTRA
 
Hacom%20pf sense%20quick start%20guide
Hacom%20pf sense%20quick start%20guideHacom%20pf sense%20quick start%20guide
Hacom%20pf sense%20quick start%20guide
HARRY CHAN PUTRA
 
Pfsense%20%20note
Pfsense%20%20notePfsense%20%20note
Pfsense%20%20note
HARRY CHAN PUTRA
 
66 pf sensetutorial
66 pf sensetutorial66 pf sensetutorial
66 pf sensetutorial
HARRY CHAN PUTRA
 
Modul 1-instalasi
Modul 1-instalasiModul 1-instalasi
Modul 1-instalasi
HARRY CHAN PUTRA
 
Modul 1-instalasi
Modul 1-instalasiModul 1-instalasi
Modul 1-instalasi
HARRY CHAN PUTRA
 
Slimsinserver2go
Slimsinserver2goSlimsinserver2go
Slimsinserver2go
HARRY CHAN PUTRA
 
Olivevme110usermanualid
Olivevme110usermanualidOlivevme110usermanualid
Olivevme110usermanualid
HARRY CHAN PUTRA
 
Modul 10 vicon
Modul 10 viconModul 10 vicon
Modul 10 vicon
HARRY CHAN PUTRA
 

More from HARRY CHAN PUTRA (20)

07 VLAN Principle and Configuration.pdf
07 VLAN Principle and Configuration.pdf07 VLAN Principle and Configuration.pdf
07 VLAN Principle and Configuration.pdf
 
12 link aggregation configuration
12 link aggregation configuration12 link aggregation configuration
12 link aggregation configuration
 
11 mac address table characteristic configuration
11 mac address table characteristic configuration11 mac address table characteristic configuration
11 mac address table characteristic configuration
 
05 interface appended characteristic configuration
05 interface appended characteristic configuration05 interface appended characteristic configuration
05 interface appended characteristic configuration
 
Bdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manualBdcom s2508 b hardware installation manual
Bdcom s2508 b hardware installation manual
 
Mplsvpn seminar
Mplsvpn seminarMplsvpn seminar
Mplsvpn seminar
 
Firewall ip filter
Firewall ip filterFirewall ip filter
Firewall ip filter
 
Zxdsl 9210 guide
Zxdsl 9210 guideZxdsl 9210 guide
Zxdsl 9210 guide
 
9210 commissioning manual
9210 commissioning manual9210 commissioning manual
9210 commissioning manual
 
Bsd routers
Bsd routersBsd routers
Bsd routers
 
Hacom%20pf sense%20quick start%20guide
Hacom%20pf sense%20quick start%20guideHacom%20pf sense%20quick start%20guide
Hacom%20pf sense%20quick start%20guide
 
Pfsense%20%20note
Pfsense%20%20notePfsense%20%20note
Pfsense%20%20note
 
66 pf sensetutorial
66 pf sensetutorial66 pf sensetutorial
66 pf sensetutorial
 
Modul 1-instalasi
Modul 1-instalasiModul 1-instalasi
Modul 1-instalasi
 
Modul 1-instalasi
Modul 1-instalasiModul 1-instalasi
Modul 1-instalasi
 
Modul 0-pengantar
Modul 0-pengantarModul 0-pengantar
Modul 0-pengantar
 
Modul 0-pengantar
Modul 0-pengantarModul 0-pengantar
Modul 0-pengantar
 
Slimsinserver2go
Slimsinserver2goSlimsinserver2go
Slimsinserver2go
 
Olivevme110usermanualid
Olivevme110usermanualidOlivevme110usermanualid
Olivevme110usermanualid
 
Modul 10 vicon
Modul 10 viconModul 10 vicon
Modul 10 vicon
 

Recently uploaded

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 

Virtual host examples_-_apache_http_server

  • 1. VirtualHost Examples - Apache HTTP Server Page 1 Apache HTTP Server Version 2.2 VirtualHost Examples This document attempts to answer the commonly -asked questions about setting up virtual hosts. These scenarios are those involving multiple web sites running on a single server, via name-based ( name-based.html) or IP- based ( ip-based.html) virtual hosts. Running several name-based web sites on a single IP address. Name-based hosts on more than one IP address. Serving the same content on different IP addresses (such as an internal and external address). Running different sites on different ports. IP-based virtual hosting Mixed port-based and ip-based virtual hosts Mixed name-based and IP-based vhosts Using Virtual_host and mod_proxy together Using _default_ vhosts Migrating a name-based vhost to an IP-based vhost Using the ServerPath directive Running several name-based web sites on a single IP address. Your server has a single IP address, and multiple aliases (CNAMES) point to this machine in DNS. You want to run a web server for www.example.com and www.example.org on this machine. Note Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries. Server configuration # Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/example 1 ServerName www.example .com # Other directives here </VirtualHost > <VirtualHost *:80> DocumentRoot /www/example 2 ServerName www.example .org # Other directives here </VirtualHost > The asterisks match all addresses, so the main server serves no requests. Due to the fact that www.example.com is first in the configuration file, it has the highest priority and can be seen as the default http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16
  • 2. VirtualHost Examples - Apache HTTP Server Page 2 or primary server. That means that if a request is received that does not match one of the specified ServerName directives, it will be served by this first VirtualHost. Note You can, if you wish, replace * with the actual IP address of the system. In that case, the argument to VirtualHost must match the argument to NameVirtualHost: NameVirtualHost 172.20.30.40 <VirtualHost 172.20.30.40> # etc ... However, it is additionally useful to use * on systems where the IP address is not predictable - for example if you have a dynamic IP address with your ISP, and you are using some variety of dynamic DNS solution. Since * matches any IP address, this configuration would work without changes whenever your IP address changes. The above configuration is what you will want to use in almost all name-based virtual hosting situations. The only thing that this configuration will not work for, in fact, is when you are serving different content based on differing IP addresses or ports. Name-based hosts on more than one IP address. Note Any of the techniques discussed here can be extended to any number of IP addresses. The server has two IP addresses. On one (172.20.30.40), we will serve the "main" server, server.domain.com and on the other (172.20.30.50), we will serve two or more virtual hosts. Server configuration Listen 80 # This is the "main" server running on 172.20.30.40 ServerName server.domain.com DocumentRoot /www/mainserver # This is the other address NameVirtualHost 172.20.30.50 <VirtualHost 172.20.30.50> DocumentRoot /www/example 1 ServerName www.example .com # Other directives here ... </VirtualHost > <VirtualHost 172.20.30.50> DocumentRoot /www/example 2 ServerName www.example .org # Other directives here ... </VirtualHost > Any request to an address other than 172.20.30.50 will be served from the main server. A request to 172.20.30.50 with an unknown hostname, or no Host: header, will be served from www.example.com. http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16
  • 3. VirtualHost Examples - Apache HTTP Server Page 3 Serving the same content on different IP addresses (such as an internal and external address). The server machine has two IP addresses (192.168.1.1 and 172.20.30.40). The machine is sitting between an internal (intranet) network and an external (internet) network. Outside of the network, the name server.example.com resolves to the external address (172.20.30.40), but inside the network, that same name resolves to the internal address (192.168.1.1). The server can be made to respond to internal and external requests with the same content, with just one VirtualHost section. Server configuration NameVirtualHost 192.168.1.1 NameVirtualHost 172.20.30.40 <VirtualHost 192.168.1.1 172.20.30.40> DocumentRoot /www/server1 ServerName server.example .com ServerAlias server </VirtualHost > Now requests from both networks will be served from the same VirtualHost. Note: On the internal network, one can just use the name server rather than the fully qualified host name server.example.com. Note also that, in the above example, you can replace the list of IP addresses with *, which will cause the server to respond the same on all addresses. Running different sites on different ports. You have multiple domains going to the same IP and also want to serve multiple ports. By defining the ports in the "NameVirtualHost" tag, you can allow this to work. If you try using <VirtualHost name:port> without the NameVirtualHost name:port or you try to use the Listen directive, your configuration will not work. Server configuration Listen 80 Listen 8080 NameVirtualHost 172.20.30.40:80 NameVirtualHost 172.20.30.40:8080 <VirtualHost 172.20.30.40:80> ServerName www.example .com DocumentRoot /www/domain-80 </VirtualHost > <VirtualHost 172.20.30.40:8080> ServerName www.example .com DocumentRoot /www/domain-8080 </VirtualHost > <VirtualHost 172.20.30.40:80> ServerName www.example .org DocumentRoot /www/otherdomain -80 </VirtualHost > <VirtualHost 172.20.30.40:8080> ServerName www.example .org DocumentRoot /www/otherdomain -8080 http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16
  • 4. VirtualHost Examples - Apache HTTP Server Page 4 </VirtualHost > IP-based virtual hosting The server has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the names www.example.com and www.example.org respectively. Server configuration Listen 80 <VirtualHost 172.20.30.40> DocumentRoot /www/example 1 ServerName www.example .com </VirtualHost > <VirtualHost 172.20.30.50> DocumentRoot /www/example 2 ServerName www.example .org </VirtualHost > Requests for any address not specified in one of the <VirtualHost> directives (such as localhost, for example) will go to the main server, if there is one. Mixed port-based and ip-based virtual hosts The server machine has two IP addresses (172.20.30.40 and 172.20.30.50) which resolve to the names www.example.com and www.example.org respectively. In each case, we want to run hosts on ports 80 and 8080. Server configuration Listen 172.20.30.40:80 Listen 172.20.30.40:8080 Listen 172.20.30.50:80 Listen 172.20.30.50:8080 <VirtualHost 172.20.30.40:80> DocumentRoot /www/example 1-80 ServerName www.example .com </VirtualHost > <VirtualHost 172.20.30.40:8080> DocumentRoot /www/example 1-8080 ServerName www.example .com </VirtualHost > <VirtualHost 172.20.30.50:80> DocumentRoot /www/example 2-80 ServerName www.example .org </VirtualHost > <VirtualHost 172.20.30.50:8080> DocumentRoot /www/example 2-8080 ServerName www.example .org </VirtualHost > Mixed name-based and IP-based vhosts On some of my addresses, I want to do name-based virtual hosts, and on others, IP-based hosts. Server configuration http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16
  • 5. VirtualHost Examples - Apache HTTP Server Page 5 Listen 80 NameVirtualHost 172.20.30.40 <VirtualHost 172.20.30.40> DocumentRoot /www/example 1 ServerName www.example .com </VirtualHost > <VirtualHost 172.20.30.40> DocumentRoot /www/example 2 ServerName www.example .org </VirtualHost > <VirtualHost 172.20.30.40> DocumentRoot /www/example 3 ServerName www.example 3.net </VirtualHost > # IP-based <VirtualHost 172.20.30.50> DocumentRoot /www/example 4 ServerName www.example 4.edu </VirtualHost > <VirtualHost 172.20.30.60> DocumentRoot /www/example 5 ServerName www.example 5.gov </VirtualHost > Using Virtual_host and mod_proxy together The following example allows a front-end machine to proxy a virtual host through to a server running on another machine. In the example, a virtual host of the same name is configured on a machine at 192.168.111.2. The ProxyPreserveHost On directive is used so that the desired hostname is passed through, in case we are proxying multiple hostnames to a single machine. <VirtualHost *:*> ProxyPreserveHost On ProxyPass / http://192.168.111.2 ProxyPassReverse / http://192.168.111.2/ ServerName hostname .example .com </VirtualHost > Using _default_ vhosts _default_ vhosts for all ports Catching every request to any unspecified IP address and port, i.e. , an address/port combination that is not used for any other virtual host. Server configuration <VirtualHost _default _:*> DocumentRoot /www/default </VirtualHost > Using such a default vhost with a wildcard port effectively prevents any request going to the main server. A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or no Host: header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file). http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16
  • 6. VirtualHost Examples - Apache HTTP Server Page 6 You can use AliasMatch or RewriteRule to rewrite any request to a single information page (or script). _default_ vhosts for different ports Same as setup 1, but the server listens on several ports and we want to use a second _default_ vhost for port 80. Server configuration <VirtualHost _default _:80> DocumentRoot /www/default 80 # ... </VirtualHost > <VirtualHost _default _:*> DocumentRoot /www/default # ... </VirtualHost > The default vhost for port 80 (which must appear before any default vhost with a wildcard port) catches all requests that were sent to an unspecified IP address. The main server is never used to serve a request. _default_ vhosts for one port We want to have a default vhost for port 80, but no other default vhosts. Server configuration <VirtualHost _default _:80> DocumentRoot /www/default ... </VirtualHost > A request to an unspecified address on port 80 is served from the default vhost. Any other request to an unspecified address and port is served from the main server. Migrating a name-based vhost to an IP-based vhost The name-based vhost with the hostname www.example.org (from our name-based ( #name) example, setup 2) should get its own IP address. To avoid problems with name servers or proxies who cached the old IP address for the name-based vhost we want to provide both variants during a migration phase. The solution is easy, because we can simply add the new IP address (172.20.30.50) to the VirtualHost directive. Server configuration Listen 80 ServerName www.example .com DocumentRoot /www/example 1 NameVirtualHost 172.20.30.40 <VirtualHost 172.20.30.40 172.20.30.50> DocumentRoot /www/example 2 ServerName www.example .org # ... </VirtualHost > <VirtualHost 172.20.30.40> DocumentRoot /www/example 3 ServerName www.example .net ServerAlias *.example .net # ... http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16
  • 7. VirtualHost Examples - Apache HTTP Server Page 7 </VirtualHost > The vhost can now be accessed through the new address (as an IP-based vhost) and through the old address (as a name-based vhost). Using the ServerPath directive We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the correct Host: header. Old HTTP/1.0 clients do not send such a header and Apache has no clue what vhost the client tried to reach (and serves the request from the primary vhost). To provide as much backward compatibility as possible we create a primary vhost which returns a single page containing links with an URL prefix to the name-based virtual hosts. Server configuration NameVirtualHost 172.20.30.40 <VirtualHost 172.20.30.40> # primary vhost DocumentRoot /www/subdomain RewriteEngine On RewriteRule ^/.* /www/subdomain/index.html # ... </VirtualHost > <VirtualHost 172.20.30.40> DocumentRoot /www/subdomain/sub1 ServerName www.sub1.domain.tld ServerPath /sub1/ RewriteEngine On RewriteRule ^(/sub1/.*) /www/subdomain$1 # ... </VirtualHost > <VirtualHost 172.20.30.40> DocumentRoot /www/subdomain/sub2 ServerName www.sub2.domain.tld ServerPath /sub2/ RewriteEngine On RewriteRule ^(/sub2/.*) /www/subdomain$1 # ... </VirtualHost > Due to the ServerPath directive a request to the URL http://www.sub1.domain.tld/sub1/ is always served from the sub1-vhost. A request to the URL http://www.sub1.domain.tld/ is only served from the sub1-vhost if the client sent a correct Host: header. If no Host: header is sent the client gets the information page from the primary host. Please note that there is one oddity: A request to http://www.sub2.domain.tld/sub1/ is also served from the sub1-vhost if the client sent no Host: header. The RewriteRule directives are used to make sure that a client which sent a correct Host: header can use both URL variants, i.e. , with or without URL prefix. Copyright 2007 The Apache Software Foundation. Licensed under the Apache License, Version 2.0. http://httpd.apache.org/docs/2.2/vhosts/examples.html 24/12/2007 00:38:16