Recommended Free Tools
In Apache HTTP Server 2.4, the default virtual host is normally the first virtual-host block Apache loads for a particular address-and-port combination. Put the site you want as the fallback first, give it an explicit ServerName and DocumentRoot, place the other sites after it, and confirm Apache’s parsed order with apachectl -S.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What “default virtual host” means in Apache
Apache does not choose one universal default site for every connection. It builds separate virtual-host sets for each address and port. A request is first assigned to the most specific set that matches its destination address and connection port. Apache then compares the request’s host name with the ServerName and ServerAlias directives in that set.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Apache HTTP Server 2.4 Reference Manual 1/3 | $29.99 | Buy on Amazon |
| 2 |
|
Apache HTTP Server Reference Manual - For Apache Version 2.2.17 | $17.61 | Buy on Amazon |
| 3 |
|
Apache HTTP Server Documentation Version 2.5 | $49.95 | Buy on Amazon |
| 4 |
|
Apache HTTP Server 2.2 Official Documentation - Volume III. Modules (A-H) | $984.26 | Buy on Amazon |
| 5 |
|
Apache HTTP Server. | $14.09 | Buy on Amazon |
As an Amazon Associate I earn from qualifying purchases.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11If a name matches, Apache serves the first virtual host in configuration order that declares that name. If no name matches, the first virtual host in the selected set becomes the fallback. This is why an unknown domain, a missing Host value, or a host name with no matching alias often opens the document root from the first block.
The address-and-port sets Apache considers
Apache evaluates virtual-host declarations in this precedence order:
#1 Best Overall
- Exact IP address and exact port
- Exact IP address with a wildcard port
- Wildcard IP address with an exact port, such as
*:80 - Wildcard IP address with a wildcard port
- The main server configuration when no virtual-host declaration matches
Only after Apache selects the most specific address-and-port set does it perform name matching. A first-listed block on *:80 is therefore the default for that set, not necessarily for a different address or port.
How the Host header is used
For HTTP requests, Apache compares the value in the Host header with ServerName and ServerAlias. The port written inside the Host header is ignored for this comparison; Apache uses the actual connection port to select the address-and-port set. Consequently, changing a host header from example.com to example.com:8080 does not make a port-8080 virtual host handle a connection that actually arrived on another port.
The recommended configuration
For ordinary name-based hosting on port 80, put the intended fallback first:
Listen 80
<VirtualHost *:80>
# This first-listed virtual host is also the default for *:80
ServerName www.example.com
ServerAlias example.com
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName other.example.com
DocumentRoot /www/otherdomain
</VirtualHost>
In this example, a request whose Host is other.example.com goes to /www/otherdomain. Requests for www.example.com, example.com, an unknown host name, or a request without a usable host name fall back to the first block and its /www/domain document root.
Rank #2
- Used Book in Good Condition
Why explicit directives matter
ServerName: declares the primary host name for the site and makes matching predictable.ServerAlias: adds alternate names, including wildcard aliases where appropriate.DocumentRoot: identifies the files Apache serves for that virtual host.Listen: ensures Apache is listening on the port represented by the virtual-host declaration.
Every name-based virtual host should declare its own ServerName. Relying on an inherited or guessed name makes it harder to understand which block should answer a request and can produce surprising fallbacks.
How to make one site the default, step by step
- Identify the exact address and port. Decide whether the fallback is for
*:80, a specific IP and port, or another set. Default selection is calculated independently for each set. - Find every virtual host in that set. Check all included Apache configuration files, not just the file you normally edit. A distribution may load site files from an include directory, and the effective order is the order Apache parses them.
- Edit the block that should be the fallback. Give it an explicit
ServerName, any requiredServerAliasvalues, and the intendedDocumentRoot. - Move that block before its peers. It must be the first listed
<VirtualHost>block matching the same address and port. Merely changing the name does not change default priority. - Keep the other sites after it. Each additional block should have its own
ServerNameand, when needed,ServerAlias. Do not place an unrelated block earlier in the same address-and-port set. - Make DNS point to this server. DNS records for every public name must resolve to an address associated with the machine. An Apache directive does not create or change DNS.
- Inspect Apache’s parsed result. Run
apachectl -S, or the equivalent control command supplied by your distribution. Read the reported default server, address, port, source file, and line order before testing from a browser.
The order shown by apachectl -S is authoritative for what the running configuration will use. If it differs from the order you expected, an include file, duplicate declaration, or disabled site file may be affecting the result.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Understanding requests that do not match a name
Unknown host names
Suppose the selected set contains two blocks, with www.example.com first and other.example.com second. A request for random.example.net does not match either ServerName or ServerAlias. Apache serves the first block, so the request receives the first site’s document root.
Missing or unusable Host values
When no usable host name is available, Apache still uses the first virtual host in the selected address-and-port set. This behavior is useful for a deliberate catch-all site, but it can expose the wrong application if the first block was ordered accidentally.
Aliases and wildcard names
ServerAlias extends the names that a block can match. Put all intended alternate names on the correct block, and use wildcard aliases only when they are genuinely meant to cover a family of host names. A name listed in a different block does not become an alias for the first site.
Address and port precedence in practice
Consider these declarations:
<VirtualHost 192.0.2.10:80>
ServerName exact.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName wildcard.example.com
</VirtualHost>
A connection to 192.0.2.10 on port 80 is eligible for the exact-address set before the wildcard-address set. The first block in the exact set therefore controls unmatched names for that connection. A connection arriving on another address may instead use the *:80 set and its own first-listed fallback.
The same principle applies when you configure more than one port: the first vhost for *:80 is not automatically the first vhost for *:443 or another port. Each set needs an intentional order and explicit names.
Normal first-listed vhost versus _default_
Apache also supports a _default_ virtual-host address, but it solves a narrower problem and does not replace the normal first-listed fallback in a name-based set.
Rank #4
- Used Book in Good Condition
| Characteristic | First-listed <VirtualHost *:80> |
<VirtualHost _default_:80> |
|---|---|---|
| Address coverage | Wildcard address for the declared port | Requests sent to an unspecified address on the declared port |
| Port coverage | The exact port in the declaration, such as 80 | The exact port in the declaration, such as 80 |
Priority relative to * |
Higher precedence than _default_ when the wildcard set matches |
Lower precedence than any matching * declaration |
Unknown Host in a name-based wildcard set |
Uses the first vhost in that set | Does not displace that first vhost |
| Typical purpose | Ordinary default or catch-all site for name-based hosting | Handling an unspecified destination address when no higher-precedence wildcard set applies |
Because any * virtual-host declaration has higher precedence than _default_, adding a _default_ block will not divert unknown host names away from a matching *:80 set. If your goal is to control the ordinary fallback for name-based hosting, reorder the first block in that set instead.
Verifying the effective default with apachectl -S
Configuration files can be misleading when several files are included. The command below asks Apache to dump its parsed virtual-host map:
apachectl -S
Use the output to check:
- Which virtual host Apache labels as the default server for each address and port
- The address and port associated with each block
- The order in which matching blocks were parsed
- The source file and line number for every declaration
If your distribution uses a different control command name, use that equivalent command with the same virtual-host dump option. A browser test alone cannot tell you whether DNS, an HTTP proxy, or Apache’s own ordering caused the result; the configuration dump gives you the server-side answer first.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshooting the wrong default site
The intended block is not listed as the default
Check that it is the first block for the exact same address-and-port combination. A block that is first in one file may be parsed after another included file. Use the source file and line information from apachectl -S to locate the declaration Apache actually sees.
Best Value
The right block is first, but the browser shows another site
Confirm that the request reaches the address and port you inspected. DNS may resolve the name to a different server or to an address with its own virtual-host set. Verify the requested name resolves to an address associated with this Apache instance, then compare that destination with the address shown by apachectl -S.
A named site is falling back unexpectedly
Compare the exact host name sent by the client with the block’s ServerName and ServerAlias. Differences in spelling, a missing alias, or a name placed on another block will prevent a match. Remember that Apache uses the real connection port, not a port textually appended to the Host value, when selecting the virtual-host set.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsAn unknown domain opens a real application
This is the expected result when that application is first in the selected set. To prevent unintended exposure, create a deliberately minimal fallback block and put it first, with a document root that contains only the response you want unknown names to receive. Keep named production sites after it and assign each one explicit names.
_default_ did not change the result
Check whether a wildcard declaration such as *:80 already matches the connection. Wildcard virtual hosts have higher precedence than _default_, so the first block in the wildcard set remains the fallback for unmatched names.
Designing a predictable multi-site configuration
Use one intentional fallback per address-and-port set. A clear arrangement usually has:
- A first block with the catch-all or default document root
- An explicit
ServerNamefor that block, even when it mainly handles unknown names - Explicit
ServerNamevalues for every other site ServerAliasentries only for names that should reach the same site- Consistent address and port declarations so you know which blocks compete for first position
Document the reason for the first block in a configuration comment. Future administrators can then distinguish a deliberate fallback from an accidentally earliest file.
Quick Recap
Final checklist
- Have you identified the exact address-and-port set?
- Is the desired fallback the first parsed virtual host in that set?
- Does every site declare an explicit
ServerName? - Are alternate names present in the correct
ServerAliasdirective? - Does DNS resolve the requested names to this server’s address?
- Did you verify the result with
apachectl -S? - Are you using
_default_only for an unspecified address case rather than to override a matching wildcard set?
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.




