Accepting selected projects for Q2 2024 Check availability →
SERVER 02SYSTEM ONLINELAST SYNC: 03:17:44RSS 2.0 — ONLINE
HALF ASSEDTECHNICAL NOTES_
EST. 1999ISSUE 04.2BEST VIEWED AT 1024 × 768
TECHNICAL NOTES / TECHNICAL NOTES / APACHE / RECORD 8352f1
[APACHE]NOTE

Name-based virtual hosts in Apache 2.0

POSTED: 14.11.2002AUTHOR: ADMIN2 MIN READCOMMENTS: 0

Several HTTP sites can share one IP address when Apache selects the website using the request’s Host header. Both DNS and the server configuration must be correct; adding a virtual host does not create a DNS record.

Match the address and port

For sites sharing port 80 on the server’s available addresses, Apache 2.0 uses NameVirtualHost *:80 with corresponding <VirtualHost *:80> blocks. Give each block a ServerName, any intended ServerAlias names and its own DocumentRoot. Check the active Listen directives as well: a virtual-host block does not by itself make Apache listen on another port.

Choose the first host deliberately

The first virtual host for an address and port acts as the default for an unrecognised hostname. Put a deliberately chosen default site there rather than whichever customer happened to be configured first. Keep separate logs while commissioning and test each alias. An address-only browser request is not a sufficient test of a name-based site.

Check the request before changing DNS again

Use a temporary hosts-file entry or a client that can send the intended Host header directly to the server address. Run the configuration syntax check and inspect the reported virtual-host mapping before reloading. For SSL sites in the usual Apache 2.0 and browser configuration, plan separate IP addresses for sites needing different certificates; the certificate is selected before the HTTP Host header arrives.

COMMISSIONING

Test an unknown hostname as well as the expected ones, and make sure it reaches the intended default. Remove workstation overrides before checking public DNS.

References

Apache 2.0 manual: name-based virtual hosting

Apache 2.0 manual: binding to addresses and ports