October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Host Several Domains on One Apache Server with Virtual Hosts

A practical guide to hosting multiple domains on one Apache server with name-based virtual hosts, including DNS, HTTP and HTTPS blocks, aliases, certificate coverage, verification, and troubleshooting.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes—one Apache server and one IP address can host several domains. The reliable pattern is name-based virtual hosting: DNS sends every domain to the server, then Apache examines the requested hostname and selects the matching <VirtualHost> block.

Create one virtual-host block for each independent website. Give every block an explicit ServerName and DocumentRoot; add ServerAlias values only for alternate names that should serve the same site. For HTTPS, create corresponding port-443 blocks and configure certificates that cover the names being served.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What “several domains on one virtual host” actually means

The phrase is often used loosely. Apache can place several domains on one server, network address, or IP, but separate websites normally use separate <VirtualHost> blocks. A single block can handle several hostnames when those names are aliases for the same site.

Name-based virtual hosting is usually simpler than assigning a separate IP address to every site. Apache first identifies the address and port that accepted the connection, then uses the hostname supplied by the request to choose among the virtual hosts attached to that address and port.

  • Independent sites: use a separate block and document root for each site.
  • Alternate names for one site: keep one block and list the extra names with ServerAlias.
  • HTTPS: repeat the mapping on port 443 and make sure the TLS certificate covers the requested name.

Prerequisite: point every domain at the Apache server

Apache configuration does not create DNS records. Before debugging virtual-host rules, create the DNS records that make each domain and alias resolve to the server’s address.

Records to create

  • An A record for each name that should resolve over IPv4.
  • An AAAA record for each name that should resolve over IPv6, when the server is reachable over IPv6.
  • Equivalent records from your DNS provider when it uses a different record interface or terminology.

Include the bare domain and the www name if both are intended to work. For example, a site represented by example.com and www.example.com needs both names to resolve before Apache can match both of them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Confirm DNS before changing Apache

Resolve every name and compare the returned address with the server’s intended public address. If one name still points to an old host, has no record, or resolves to a different address, Apache on the correct server cannot receive that request. DNS propagation and cached answers can also make a recent change appear inconsistent; test each name separately and record which address it returns.

Choose the layout before writing configuration

The correct layout follows the relationship between the domains, not the number of names. The choices below prevent a common mistake: putting unrelated sites in one document root merely because they share an IP.

Decision Use this when Operational effect
Separate document roots Domains are independent websites Each site gets its own DocumentRoot, content tree, and virtual-host block.
Shared content with aliases Several names are alternate entry points for one website One block serves the same files and lists the additional names with ServerAlias.
HTTP-only blocks The service is intentionally available only on port 80 Only *:80 mappings are needed; there is no TLS selection for that service.
HTTP plus HTTPS blocks Visitors should reach the site over both protocols Define matching port-80 and port-443 mappings and handle certificate coverage separately.
Explicit aliases Multiple names should display the same site without changing the address ServerAlias handles the names inside the same virtual host.
Redirects One public name should send visitors to another canonical URL The request is deliberately moved to a different URL rather than simply served as an alias.
Isolated logs and access controls Sites have different operators, privacy needs, or security boundaries Keep the sites’ operational records and restrictions separate.
Shared logs and access controls One team administers the sites under a common policy Centralized handling is simpler, but an incident or policy change can affect all sites.

Do not use an alias to hide that two sites are independent. If they need different files, permissions, access rules, or operational ownership, give them different blocks and roots.

Create the HTTP virtual hosts

For a basic HTTP setup, add one <VirtualHost *:80> block for each distinct website. Apache requires an explicit ServerName and a DocumentRoot in each name-based virtual host. Add aliases only where they belong to that same site.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example
</VirtualHost>

<VirtualHost *:80>
    ServerName example.net
    ServerAlias www.example.net
    DocumentRoot /var/www/example-net
</VirtualHost>

What each directive does

  • <VirtualHost *:80> groups rules for requests received on port 80 on any local address.
  • ServerName is the primary hostname Apache should match for that site.
  • ServerAlias adds other hostnames that should reach the same document root.
  • DocumentRoot identifies the files Apache serves for the block.

Replace the example names and paths with your real domains and directories. Keep each independent site’s files in its own root. A typo in a hostname or path can make a valid request land in the wrong block or return content from an unexpected directory.

One site with several names

If several domains are simply alternate names for one website, place them in one block as aliases rather than duplicating the document root. The primary name belongs in ServerName; the other names belong in ServerAlias. This keeps one content location while making the intended hostname list visible in the configuration.

Several independent sites

Give every independent site its own block, primary name, and document root. This is the arrangement shown for example.com and example.net above. It also makes later changes safer: changing one site’s files or rules does not silently replace another site’s content.

How Apache decides which site to serve

Understanding the selection order explains most “wrong site” reports.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Apache groups configured virtual hosts by the local address and port that received the connection.
  2. For HTTP, it compares the request’s Host header with the ServerName and ServerAlias values in that group.
  3. For an SSL connection, the TLS SNI hostname participates in selecting the HTTPS virtual host; the certificate presented during the TLS handshake must also cover the requested name.
  4. Apache processes matching name-based hosts in configuration order. When more than one entry could match, the first matching name is used.
  5. If no ServerName or ServerAlias matches, the first virtual host listed for that address-and-port pair becomes the fallback.

The fallback rule is why a request can show a real website even though its hostname was never configured: Apache is serving the first block for that address and port. Treat the first block as an intentional default, not as an accidental place to store a site.

Why the same IP is enough

With name-based hosting, the IP address identifies the Apache server, while the hostname identifies the site inside Apache. The domains do not need separate IPv4 addresses merely because they have separate virtual hosts. They do, however, need DNS records that lead the request to that server.

Add HTTPS without mixing up TLS and virtual-host mapping

HTTPS requires the same hostname-to-site plan plus TLS configuration. Define corresponding <VirtualHost *:443> blocks for the HTTPS names you intend to serve.

Port 443 blocks

Each HTTPS block should identify its site with an explicit ServerName, list any same-site aliases with ServerAlias, and point at the intended content. Keep the port-80 and port-443 hostname sets aligned unless you deliberately want different behavior for the two protocols.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache uses the request’s SNI hostname to select among HTTPS virtual hosts after selecting the address and port. A certificate is a separate requirement: it must cover the hostname the browser requests. A correct virtual-host match cannot compensate for a certificate that omits that name.

Certificate strategy

Choose a certificate arrangement that covers every HTTPS name: a certificate can cover one name or multiple names, depending on the certificate you obtain. Certificate issuance, storage, and renewal are separate operational tasks from Apache’s virtual-host mapping. Test renewal independently so a future certificate change does not leave one alias mismatched.

HTTP and HTTPS are separate listeners

A working *:80 block does not automatically create a working *:443 site. Configure and verify both address-and-port groups. If HTTP works but HTTPS shows the wrong content, inspect the port-443 order, the SNI name, and certificate coverage rather than changing the port-80 block.

Verify Apache’s parsed configuration

Do not rely on the file you edited alone; verify the configuration Apache actually parsed. On Unix-like systems, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
apachectl -S

On Windows, use:

httpd.exe -S

The dump should show the address-and-port groups, every ServerName and ServerAlias, the order in which the hosts were read, and the default host for each group. Compare that output with your intended design.

Verification sequence

  1. Confirm each domain and alias resolves to the intended server address.
  2. Check that every independent site has its own ServerName and DocumentRoot.
  3. Check that aliases appear under the block whose content they should serve.
  4. Run the appropriate configuration-dump command and inspect the reported order and fallback host.
  5. Test HTTP names individually, then test HTTPS names individually.
  6. For an HTTPS failure, inspect both the selected virtual host and the certificate presented for the SNI hostname.

Use a deliberately unique test file in each document root while validating. A distinctive response makes it obvious which root Apache selected and avoids confusing identical default pages.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a domain that shows the wrong site

Symptom Likely cause What to inspect Correction
Every domain shows the same site The requested name is not matching a configured host, so the first host is acting as fallback DNS result, exact Host name, and apachectl -S or httpd.exe -S output Add the missing ServerName or ServerAlias, or correct the DNS record.
Only one alias fails The alias is absent or attached to another block The spelling of the hostname and the block containing ServerAlias Put the alias in the block for the intended site.
HTTP is correct but HTTPS is wrong The port-443 group has different order or hostname coverage The HTTPS blocks, SNI hostname, and certificate Align the 443 mapping with the intended site and use a certificate covering that name.
A domain reaches another server DNS still points elsewhere The resolved A/AAAA address for the domain Update the DNS record and wait for caches to expire before retesting.
A newly edited block has no effect Apache parsed a different file or configuration order than expected The configuration dump rather than only the source file Find the loaded block, correct the active configuration, then verify the parsed result again.
Two sites share files unexpectedly They use the same DocumentRoot or were placed under one alias block The document-root paths and relationship between the domains Separate the roots and blocks when the sites are independent.

Check the hostname actually sent

A browser’s visible URL is not enough when diagnosing a proxy, redirect, or test tool. Inspect the HTTP Host header that reached Apache. For HTTPS, also establish which SNI hostname was sent during the TLS handshake. A mismatch between the intended name and the name delivered to Apache produces a correct fallback response from Apache’s point of view.

Check order before rewriting everything

If the dump shows the expected names but the response is still wrong, inspect the order of the blocks for that address and port. An earlier matching alias can capture a request before a later block is considered. Keep aliases narrow and avoid listing a name in more than one site.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Aliases, canonical names, and redirects

ServerAlias is a hostname-to-the-same-site mapping. It lets two names serve one document root while preserving the requested URL. A redirect is a different decision: it tells the client to request another URL, usually to establish one canonical public name.

Choose an alias when both names are valid entry points for the same site. Choose a redirect when only one name should remain public or when you need the browser, search engine, and links to converge on a canonical address. Do not list a name as an alias in one block and redirect it from another block; that creates an avoidable ordering conflict.

Logging and access-control boundaries

Shared content does not automatically mean shared operations. Decide whether the domains need isolated or shared logging and access controls before deployment.

When to isolate

  • Different sites have different administrators or users.
  • One site may need stricter access restrictions than another.
  • You need to attribute requests, incidents, or resource use to a specific site.
  • A change for one domain must not alter another domain’s records or protections.

When sharing is reasonable

Shared handling can be simpler when one team owns every site and applies one policy. Make the choice deliberate: a common policy means a configuration mistake or access change can affect all domains in the group.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A practical deployment checklist

  1. List every public hostname, including bare and www forms that should work.
  2. Mark each hostname as an independent site, an alias, or a name that should redirect.
  3. Choose a document root for each independent site.
  4. Create the required A, AAAA, or equivalent DNS records and confirm they resolve to the Apache server.
  5. Write one explicit port-80 virtual-host block per independent site.
  6. Put same-site alternate names in ServerAlias rather than creating duplicate roots.
  7. Create corresponding port-443 blocks for HTTPS names.
  8. Obtain and maintain certificate coverage for every HTTPS hostname.
  9. Run apachectl -S or httpd.exe -S and verify names, paths, order, and defaults.
  10. Test each hostname over HTTP and HTTPS, checking the delivered Host and SNI names when a result is unexpected.
  11. Review logging and access-control boundaries so the operational design matches the ownership of the sites.

Common design mistakes to avoid

  • Expecting Apache to create DNS: virtual-host blocks only describe how Apache handles requests that reach it.
  • Using one block for unrelated websites: aliases are for alternate names of one site, not a substitute for separate roots.
  • Omitting ServerName: an explicit primary name makes matching and diagnostics predictable.
  • Forgetting port 443: an HTTP mapping does not configure HTTPS.
  • Ignoring the first-host fallback: unmatched names will still receive the first block for the address and port.
  • Checking only a browser page: inspect the parsed configuration, DNS result, and delivered hostname when the response is surprising.
  • Treating certificates as virtual-host rules: correct matching and valid certificate coverage are separate requirements.

Final perspective

Hosting several domains on one Apache server is a mapping problem with three layers: DNS sends each name to the server, Apache maps the request hostname to a virtual-host block, and HTTPS adds SNI and certificate coverage for secure connections. Keep independent sites in separate blocks and roots, use aliases only for genuinely shared content, verify the parsed order, and make the fallback host intentional. That structure scales from two domains to many without requiring one IP address per site.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.