To host several websites on one Apache server, point each domain to the server in DNS, then configure a name-based <VirtualHost> for each site. Apache uses the requested hostname to choose the matching site; if no hostname matches, it serves the first eligible virtual host for that address and port. This is the usual starting point because multiple names can share one IP address.
How Apache virtual hosts let one server host multiple websites
A virtual host lets one Apache HTTP Server handle more than one website on a machine. In a typical name-based setup, several domains share an IP address. The browser connects to that address and includes the requested hostname in its HTTP request; Apache uses the hostname to select a site. Apache’s Version 2.4 virtual host overview describes name-based hosting as usually simpler because multiple hostnames can share an address.
There are two separate pieces to configure:
- DNS directs each hostname to an address for the server. Apache configuration alone cannot make a domain resolve to that server.
- Apache maps each hostname to the appropriate site configuration and file directory.
The example below is for plain HTTP on port 80. The domain names and filesystem paths are illustrative; replace them with the names and paths used on your server.
Configure a name-based virtual host
Use an explicit ServerName and DocumentRoot in each virtual-host block. Add a ServerAlias when another hostname, such as the bare domain, should serve the same site.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Dell PowerEdge R730xd 24B SFF 2U Server
- 2x Intel Xeon E5-2690 v4 2.6Ghz 14-Core (28-cores Total)
- 128GB DDR4 RAM – 4x 1.2TB 10K SAS 2.5” 12Gb/s
- Dell H730P mini 2GB 12Gb/s RAID
- 2x 750W PSU - 2x 10Gb SFP+ 2x 1Gb (RJ45) NIC
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot "/var/www/example"
</VirtualHost>
<VirtualHost *:80>
ServerName www.other.example
DocumentRoot "/var/www/other"
</VirtualHost>
<VirtualHost *:80>says these blocks apply to the applicable local address on port 80. The wildcard does not make Apache listen on a port by itself;Listencontrols the addresses and ports on which Apache listens.ServerNameidentifies the primary hostname for that site.ServerAliaslists additional names that should reach the same virtual host.DocumentRootspecifies the directory from which that site’s files are served.
Apache’s name-based virtual-host guide explains how hostnames are associated with virtual hosts. This example covers the basic hostname-to-site mapping only; it does not configure HTTPS, which requires its own listener and TLS configuration.
How Apache selects a virtual host—and what happens when none matches
Apache does not compare every configured hostname without regard to the connection. It first finds the best match for the connection’s destination address and port. Among the eligible virtual hosts at that address and port, it compares the requested hostname with each ServerName and ServerAlias. The first hostname match is used. For SSL connections, the client’s TLS SNI hostname is also used in virtual-host selection. Apache documents this sequence in How the server selects the proper name-based virtual host.
Rank #2
- PROCESSOR & MEMORY: Powered by an Intel Xeon Silver 4112 2.60GHz CPU and 16GB DDR4 RAM for reliable server-grade performance
- STORAGE CAPACITY: Equipped with 32TB total storage via four 8TB 12Gb/s SAS hard drives for high-throughput data handling
- RAID CONTROLLER: Features the PERC H740P RAID controller, enabling advanced data protection and flexible storage configuration
- POWER SUPPLY: Dual 550W redundant power supply units ensure continuous uptime and protection against single power source failure
- FLEXIBLE DEPLOYMENT: Ships with no OS installed, allowing administrators to install their preferred operating system or hypervisor
If no configured name matches, Apache uses the first virtual host in the matching address-and-port set as the default. As a result, an unknown or misspelled hostname may show a real site rather than an error page. The main server configuration is not guaranteed to catch unmatched names when a matching wildcard virtual-host set exists.
To make this fallback intentional, decide which site—or a separately configured default site—should occupy the first position for each address and port. Review your configuration for missing or mistyped names, overlapping aliases, and blocks that listen on a different address or port than the request uses.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #3
Name-based vs. IP-based virtual hosts
| Consideration | Name-based virtual hosts | IP-based virtual hosts |
|---|---|---|
| How Apache selects the site | By hostname, after matching the connection’s destination address and port. | By a different destination IP address or port combination. |
| Address use | Several hostnames can share one IP address. | Each virtual host needs a distinct address-and-port combination; multiple TCP ports on one IP also count as IP-based hosting in Apache’s terminology. |
| Typical fit | Hosting several ordinary domains on one server. | A deployment that specifically needs separation by interface, address, or port. |
| Main setup concern | DNS plus explicit Apache ServerName and, where needed, ServerAlias values. |
Address and port allocation, along with matching listener configuration. |
Apache’s name-based guide and IP-based virtual-host guide explain the distinction. Unless a deployment specifically requires separate address-and-port combinations, name-based hosting is generally the simpler choice.
Check how Apache parsed the configuration
Use Apache’s virtual-host dump to see which addresses, ports, and server names it recognizes:
Rank #4
- WIRED NETWORK USB PRINT SERVER: Connect a single USB 2.0 printer to a wired Ethernet LAN (RJ45); 10Base-T, 100Base-TX auto-sensing to ensure a reliable connection, letting you print from any network computer, across the office or over the Internet
- MANUAL NETWORK SETUP REQUIRED: Configuration via web interface (static IP or DHCP) using LPR queue “LP1"; Not plug-and-play, requires intermediate network knowledge for installation; Access our online FAQs for additional helpful tips and instructions
- USB PRINTER COMPATIBILITY: Works with most USB 2.0 printers using standard drivers; Not compatible with USB hubs, multi-function printers with proprietary drivers, or printers requiring full bi-directional communication
- COMPATIBILITY: The USB to Ethernet print server is USB 2.0 compliant and works with macOS and Windows; It also supports LPR network printing and Bonjour Print Services for broad compatibility; Included software is compatible with Windows only
- PRINT FROM ANYWHERE: Print from any computer connected to the Ethernet; This print server doesn’t require a wired connection to a computer, however it must be connected to your networking device (eg. router or switch) with the included RJ45 network cable
apachectl -S
On Windows, use:
httpd.exe -S
Apache’s virtual-host selection guide documents these commands. They show Apache’s view of the configuration; they do not test whether public DNS points a domain to the intended server, whether the site files are present, or whether the filesystem permissions allow Apache to read them. Check DNS resolution separately, then verify the document root and access permissions if Apache’s parsed host mapping is correct but the site still fails.
Troubleshoot a site that shows the wrong content
- An unknown hostname shows another site: Check the first virtual host for the relevant address and port; unmatched names go to that default.
- A domain shows the wrong configured site: Check its
ServerNameandServerAliasentries, look for overlapping aliases, and confirm the request reaches the intended address and port. - Apache seems to ignore a block: Run
apachectl -Son Unix-like systems orhttpd.exe -Son Windows to inspect the parsed virtual-host map. - The hostname mapping looks right but the site is unreachable: Verify DNS separately, then check that the configured
DocumentRootexists and that Apache can access its files.
Do not add the obsolete NameVirtualHost directive
For Apache 2.4, NameVirtualHost has no effect and should not be added to a new configuration. Apache says repeated address-and-port combinations enable name-based matching automatically in versions 2.3.11 and later; the directive was required before 2.3.11. See Apache’s NameVirtualHost documentation before adapting older configuration examples.
Best Value
When many hostnames need a generated layout
For a large, predictable set of hostnames, Apache’s mod_vhost_alias can derive document paths from the requested hostname with directives such as VirtualDocumentRoot. This is a different path-selection model from writing a separate document root for each small set of sites. Consult the mod_vhost_alias documentation to determine whether hostname-derived paths suit the directory structure and administration of your deployment.
Platform-specific configuration is separate
The virtual-host directives are Apache configuration, but where configuration files live, how they are enabled, and how Apache is reloaded depend on the operating system and package. The title does not identify a platform, so there is no single portable file path or reload command to give here. Use the configuration layout and service procedure for your Apache installation, then inspect the result with the platform-appropriate virtual-host dump command.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




