DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk12 min

How to Host Multiple SSL Domains on Apache With the Right DocumentRoot

A practical Apache guide to serving multiple SSL domains on one IP: build separate HTTPS virtual hosts, map each hostname to the right DocumentRoot, configure certificates and DNS, and diagnose fallback vhost errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Host each domain in its own name-based HTTPS virtual host. Give every <VirtualHost *:443> block an explicit ServerName, only the ServerAlias names that belong to that site, that site’s DocumentRoot, its TLS certificate, and a matching <Directory> permission block. Point every domain’s DNS records at the Apache server, enable TLS and the sites, then validate the active vhost map. Apache uses SNI to choose the certificate during the TLS handshake and the hostname to choose the matching virtual host; when no name matches, the first vhost for that address and port is used as the fallback.

The model: one HTTPS virtual host per site

Apache can serve many domains from one IP address and TCP port by using name-based virtual hosting. The important boundary is the HTTPS virtual host, not the server-wide configuration. Each independent site should have its own <VirtualHost *:443> block with a unique ServerName and an explicit DocumentRoot.

As an Amazon Associate I earn from qualifying purchases.

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

Inside each <VirtualHost> block, Apache requires at minimum a ServerName to designate which host is served and a DocumentRoot to show where that host’s content lives.

For a request to https://example.com/, Apache first groups listeners by IP address and port, then compares the requested hostname with ServerName and ServerAlias. The selected block supplies the filesystem root, certificate, logs, and other site settings. If no hostname matches, Apache serves the first virtual host in that IP-and-port group. That fallback behavior is the most common reason a correctly configured domain appears to use another site’s DocumentRoot.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
Hostname HTTPS virtual host DocumentRoot Certificate Logs
example.com and www.example.com <VirtualHost *:443> with ServerName example.com /var/www/example.com/public Certificate covering example.com and its intended aliases example.com access and error logs
example.org and www.example.org A separate <VirtualHost *:443> with ServerName example.org /var/www/example.org/public Certificate covering example.org and its intended aliases example.org access and error logs

Do not put two unrelated sites in one block merely because they share an IP. Put aliases in the same block only when those names should serve the same files and application.

Prerequisites to check before editing Apache

Configuration cannot compensate for a missing DNS record, a certificate that does not cover the requested name, or a listener that is not reachable on port 443. Check these items first:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • DNS: Every hostname you intend to serve must have an A record, an AAAA record, or another DNS arrangement that resolves to this Apache server. Apache configuration does not create DNS entries.
  • Reachability: Apache must listen on the address and port clients use, normally TCP 443 for HTTPS and TCP 80 for the redirect.
  • Certificates: Obtain a certificate and private key for each domain, or use a wildcard or Subject Alternative Name certificate whose names include every hostname in that virtual host.
  • Apache TLS support: The SSL module and an SNI-capable TLS stack are required when several certificates share one IP and port.
  • Filesystem: Each DocumentRoot must exist, contain the intended site files, and be searchable by the Apache user through every parent directory.
  • Authorization: A matching <Directory> block must permit access, for example with Require all granted where public access is intended.
  • Isolation: Keep unrelated sites in separate directories and use separate logs so a request can be traced to one configuration.

Choose a predictable directory layout

A per-domain layout makes a wrong-root error obvious and limits accidental cross-site access. For example:

/var/www/example.com/public/index.html
/var/www/example.org/public/index.html

The final directory named by DocumentRoot is the directory Apache serves for the URL path /. If the browser requests /images/logo.svg, Apache looks for that path below the selected root. A different root means a different site, even when both domains point to the same server.

Create the directories and place a distinctive test file in each one before troubleshooting vhosts. A page containing the domain name, such as example.com test, prevents you from mistaking a cached or generic index page for the selected site.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Write the HTTP redirect and HTTPS virtual hosts

Use a port-80 vhost to redirect clear-text requests and a separate port-443 vhost for each domain. Repeat aliases in the redirect block so every intended HTTP hostname reaches the correct HTTPS URL.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
# HTTP listener and redirect vhost
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect permanent / https://example.com/
</VirtualHost>

# Domain 1
<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    SSLEngine On
    SSLCertificateFile /etc/ssl/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/ssl/example.com/privkey.pem
    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
    <Directory /var/www/example.com/public>
        Require all granted
    </Directory>
</VirtualHost>

# Domain 2
<VirtualHost *:443>
    ServerName example.org
    ServerAlias www.example.org
    DocumentRoot /var/www/example.org/public
    SSLEngine On
    SSLCertificateFile /etc/ssl/example.org/fullchain.pem
    SSLCertificateKeyFile /etc/ssl/example.org/privkey.pem
    ErrorLog ${APACHE_LOG_DIR}/example.org-error.log
    CustomLog ${APACHE_LOG_DIR}/example.org-access.log combined
    <Directory /var/www/example.org/public>
        Require all granted
    </Directory>
</VirtualHost>

The certificate paths above are examples, not universal locations. Substitute the paths created by your certificate issuer and operating system. The private-key file should be readable by Apache’s TLS process but not broadly readable by untrusted users.

Keep aliases intentional

ServerName is the primary name. Add a ServerAlias only when that hostname should serve the same application and files. If www.example.com should redirect to the apex name rather than render the same site directly, create a deliberate redirect policy instead of silently treating it as an alias.

Match the Directory path exactly

The path in <Directory> must match the real DocumentRoot, including case and every parent directory. Granting access to /var/www/example.com while serving /var/www/example.com/public can work only if the effective authorization also covers the child; an exact block is easier to audit. Conversely, a typo in the Directory path can leave the correct vhost selected but produce a 403 response.

Enable TLS, sites, and listeners

Enable the SSL module and the configuration files using your distribution’s tools. On Debian- and Ubuntu-style systems, a typical sequence is:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
  1. Enable the SSL module with sudo a2enmod ssl.
  2. Save each site in its own configuration file under the distribution’s Apache sites directory, then enable it with sudo a2ensite example.com.conf and sudo a2ensite example.org.conf.
  3. Confirm Apache has a listener for HTTPS. The active configuration should include a Listen 443 directive, either directly or through the distribution’s SSL configuration.
  4. Check syntax with sudo apachectl configtest. Do not reload until it reports a successful syntax check.
  5. Inspect the assembled vhost map with sudo apachectl -S. Command names and site-enable helpers vary by distribution; use the equivalent command provided by your package.
  6. Reload Apache, for example with sudo systemctl reload apache2. A reload applies configuration without unnecessarily terminating existing connections.

On systems that use a different service name or do not provide a2ensite, edit the enabled configuration location documented by that distribution and use its corresponding syntax-test and reload commands. The principles remain the same: load the SSL module, load every vhost, test, inspect, and reload.

Why SNI is required for different certificates on one IP

With ordinary HTTP, Apache can read the Host header after the connection is established. TLS certificate selection happens earlier, during the handshake, before that HTTP header exists. Server Name Indication (SNI) places the requested hostname in the TLS handshake so Apache can select the correct SSL virtual host and present the corresponding certificate.

SNI allows many virtual hosts to share one IP address and port while retaining unique certificates and independent configuration. Modern browsers and clients generally support it, but a legacy non-SNI client cannot reliably select among multiple certificate-based vhosts on the same address. If such clients are a requirement, use a certificate covering all required names, a separate IP address, or a separate port and endpoint design.

The first SSL vhost is also significant. If a client supplies no hostname, does not support SNI, or supplies a name that matches no ServerName or ServerAlias, Apache uses the first vhost for that address and port. Put a deliberate, restrictive default first rather than allowing an unknown hostname to expose a real site’s content.

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

Validate DNS, certificates, and content separately

Testing one layer at a time prevents a DNS problem from being misdiagnosed as a DocumentRoot problem.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
  1. Resolve the names: Check the A and AAAA answers for every hostname. They should lead to the server that runs these vhosts. If IPv6 points elsewhere while IPv4 points here, some users will consistently reach a different server.
  2. Test the HTTP redirect: Request each port-80 hostname and confirm it redirects to the intended HTTPS hostname, not to another domain.
  3. Test certificate identity: Open each HTTPS name and inspect the certificate’s Subject Alternative Name list. The requested hostname must be covered.
  4. Test a unique file: Request a file that exists only under the selected domain’s root. This proves the DocumentRoot, rather than just the certificate, is correct.
  5. Read the per-site logs: A request to example.com should appear in example.com’s access log. An entry in another site’s log points to hostname matching, listener, or fallback ordering rather than application code.
  6. Compare the live map: Run apachectl -S after every significant edit and verify both *:80 and *:443 contain the expected names, files, and order.

For a server-side test that bypasses public DNS while preserving the TLS hostname, a client can use a hostname-to-address override such as curl --resolve example.com:443:203.0.113.10 https://example.com/. Replace the example address with the server’s real test address; do not publish documentation that points readers at an address they do not control.

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

Fixing the wrong DocumentRoot

When one domain displays another domain’s files, work through these checks in order.

1. Confirm the exact hostname

Check the address bar, redirects, and the requested spelling. example.com, www.example.com, and a typo or alternate subdomain are separate names. Add the alternate name to ServerAlias only if it is supposed to serve that same root. Otherwise create its own vhost or an explicit redirect.

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

2. Confirm DNS, including IPv6

Apache does not publish DNS. Verify every A and AAAA record resolves to this host. A stale record, a second server, or an AAAA record pointing elsewhere can make a perfectly correct local configuration appear broken.

3. Confirm the address and port group

An HTTPS request must reach the vhost group that listens on the address and port the client uses. Make sure the block is <VirtualHost *:443>, or uses the actual local address bound to 443, and make sure Apache is listening on 443. A block written only for port 80 cannot answer an HTTPS request.

4. Inspect vhost ordering

If the hostname is absent from every ServerName and ServerAlias, Apache selects the first vhost in the matching address-and-port group. Reorder the files or add the missing name. Do not rely on alphabetical file ordering as an undocumented security policy; make the intended default explicit and verify it with the vhost-dump command.

5. Check SNI and the certificate together

If the certificate is valid for one domain but the other domain’s content appears, the client may be reaching the first SSL vhost because it did not send SNI or because the requested name is not configured. Modern clients should send SNI, but legacy clients need a multi-name certificate or a separate endpoint.

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

6. Verify the root and authorization

Confirm that every DocumentRoot exists, contains the expected index or application entry point, and has a matching <Directory> rule with the required access permission. A correct vhost with a missing directory commonly yields a 404 or startup warning; a directory blocked by authorization commonly yields 403.

7. Read the right logs

Separate ErrorLog and CustomLog directives make selection visible. Look at the timestamped request in each site’s access log and any corresponding error entry. If the request is logged only by the first site’s files, Apache selected that vhost before it considered the filesystem path.

Choosing between shared IPs, certificates, and roots

SNI is normally the simplest design, but the alternatives matter when client compatibility, certificate management, or network policy changes.

Design choice Advantages Costs and limits When it fits
One IP, one certificate per domain, SNI vhosts Independent certificates, roots, logs, and settings; conserves IPv4 addresses. Requires SNI-capable clients and careful hostname matching. The normal design for current browsers and APIs.
One IP with a wildcard certificate One certificate can cover many names within the wildcard’s scope. Wildcard coverage has naming limits and does not automatically cover unrelated domains or every subdomain level. Several related subdomains share a certificate-management policy.
One IP with a Subject Alternative Name certificate Several explicitly listed names can use one certificate, including names from different subdomains. Adding or removing names requires certificate reissuance and careful inventory. A controlled set of names must work with clients that benefit from one certificate.
Separate IP addresses Separates listeners and can support clients or policies that cannot use SNI. Consumes addresses and adds network configuration and certificate endpoints to maintain. Legacy-client compatibility or strict network isolation is required.
Separate ports Separates endpoints without additional IP addresses. Users must specify nonstandard ports, and normal HTTPS expectations and firewalls may not fit. Controlled internal services rather than ordinary public websites.
Shared filesystem root Fewer directories to create. Sites can overwrite or expose one another’s files, and a root-selection mistake affects all names. Only when the names intentionally serve one application and share content.
Separate filesystem roots and logs Clear ownership, easier backups and troubleshooting, and better isolation. More directories, certificates, and configuration entries to maintain. Independent domains, applications, or teams.

Use a deliberate default vhost

Because unmatched names go to the first vhost, the default is a security and troubleshooting decision. A minimal default can reject unknown hostnames rather than serving a production site’s files. For example, place a first *:443 block with a certificate chosen for the server’s administrative name and a non-public or empty root, then place customer or production vhosts after it. The exact rejection policy depends on the application and Apache version; the essential point is that an accidental hostname must not reveal a real site’s content.

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

Apply the same thinking to port 80. An unknown HTTP hostname should not be redirected into a legitimate domain unless that behavior is intentional. Keep the redirect target tied to the names declared in that redirect vhost.

Operational practices that prevent future mix-ups

  • One file per domain: Name configuration files after the primary domain so the enabled set is easy to audit.
  • One root per independent site: Avoid copying an index file between roots as a substitute for fixing vhost selection.
  • One log pair per domain: Keep access and error records separate, and retain enough history to correlate configuration changes with failures.
  • Document certificate coverage: Record which names each certificate covers and where its key and chain files are stored.
  • Test after every change: Run the syntax check, inspect the vhost map, reload, and request a domain-specific test file.
  • Keep aliases narrow: An alias is a routing rule. Broad or accidental aliases are a common way to make a domain appear to use the wrong root.
  • Account for both address families: If you publish AAAA records, ensure IPv6 reaches the same Apache configuration and firewall policy as IPv4.

Configuration checklist

  1. Create a separate directory and test file for each independent domain.
  2. Verify A and AAAA records for every primary name and intended alias.
  3. Obtain certificates whose names cover the HTTPS hostnames.
  4. Create one port-80 redirect vhost per redirect policy.
  5. Create one port-443 vhost per site with explicit ServerName, intentional aliases, DocumentRoot, TLS directives, logs, and Directory authorization.
  6. Enable the SSL module, site files, and listeners required by your distribution.
  7. Run the syntax test before reloading.
  8. Use the vhost-dump command to verify names, ports, files, and first-vhost order.
  9. Reload Apache and test each domain over HTTP and HTTPS.
  10. Check the certificate, unique content, and per-site logs before declaring the setup complete.

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 from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.