Embedthis Appweb 4.3.4
Home > Users Guide > Virtual Hosts

# Quick Nav

# See Also

# Virtual Hosts

Virtual hosting is the capability of a single system to serve multiple web domain addresses. For example, a single server could respond to requests for www.acme.com and www.coyote.com. This is clearly useful for public web sites, but virtual hosting is also an excellent technique to manage separate content within a single domain. For example, the administration interface and the user interfaces can be implemented as separate virtual hosts.

## Configuration Directives

Virtual hosts are created by grouping configuration directives within a VirtualHost directive block. Directives within the block apply only to the virtual host.

    <VirtualHost 206.148.97.56>
        ServerName www.acme.com
        Documents /var/www/acmeDocs
          ...
    </VirtualHost>

Before declaring a VirtualHost directive for name-based virtual hosting, you must use a NameVirtualHost directive. This specifies that the given IP address will use name-based hosting.

## Name-based Virtual Hosts

Name-based virtual hosts allow multiple virtual hosts to share an IP address by using the HTTP Host header to distinguish which virtual host should service the request.

NOTE: Name-based virtual hosting cannot be used with the SSL protocol. You must use IP-based hosting.

### Example

    NameVirtualHost 206.148.97.56
    <VirtualHost 206.148.97.56>
        ServerName www.acme.com
        Documents /var/www/acme
        ...
    </VirtualHost>
    <VirtualHost 206.148.97.56>
        ServerName www.coyote.com
        Documents /var/www/coyote
        ...
    </VirtualHost>

In this example www.acme.com and www.coyote.com share the IP address 206.148.97.56. Note that the IP address specified by the NameVirtualHost directive must match the IP address in the VirtualHost directive. You may specify port numbers with the IP addresses if you require a port other than port 80.

WARNING: Some very old clients may not include the Host header in their HTTP request and so may not be able to use Name-based virtual hosting.

## IP-based Virtual Hosts

IP-based virtual hosts allow multiple virtual hosts to be supported on a single server. Each IP-based virtual host consumes a separate IP address. The SSL protocol is supported with IP-based virtual hosting.

    <VirtualHost 206.148.97.56>
        ServerName www.acme.com
        Documents /var/www/acme
        ...
    </VirtualHost>
    <VirtualHost 206.148.97.57>
        ServerName www.coyote.com
        Documents /var/www/coyote
        ...
    </VirtualHost>

In this example, www.acme.com and www.coyote.com are separate virtual hosts.

© Embedthis Software LLC, 2003-2013. All rights reserved. Embedthis, Appweb, ESP, Ejscript and Embedthis GoAhead are trademarks of Embedthis Software LLC.