October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober 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 Fix an Apache Virtual Host Pointing to the Wrong DocumentRoot

Apache usually serves the wrong DocumentRoot because it selected another virtual host. Follow this diagnostic sequence to verify IP and port matching, hostnames, activation order, directory rules and configuration reloads.
Length9 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache usually is not ignoring DocumentRoot. It is serving a different virtual host. Apache first selects the best matching IP-address and port pair, then compares the request’s hostname with ServerName and ServerAlias. If no name matches, Apache serves the first virtual host listed for that address and port—the default for unmatched requests. That explains a familiar set of symptoms: the Apache welcome page, another site’s files, or a directory that does not match the configuration you edited.

Fix the selection path in order: inspect Apache’s parsed vhost map, verify DNS and the request’s port, make every hostname explicit, confirm the site is enabled and ordered correctly, align DocumentRoot with its <Directory> permissions, then test and reload the configuration. The procedure below applies to name-based HTTP virtual hosts and notes where Debian/Ubuntu and Fedora/RHEL layouts differ.

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.

How Apache chooses the directory it serves

A request does not begin with a directory lookup. Apache first determines which virtual-host set can answer the connection. The set is constrained by the destination IP address and TCP port. Only after that does Apache inspect the hostname supplied in the request, normally the HTTP Host header, against each candidate’s ServerName and ServerAlias.

  1. IP and port selection: Apache finds the most specific <VirtualHost> address and port combination that matches the connection.
  2. Hostname selection: Within that set, it looks for an exact ServerName or ServerAlias match.
  3. Fallback: If no hostname matches, Apache uses the first listed virtual host for that address and port.
  4. File serving: The selected block’s DocumentRoot, rewrite rules, aliases and directory permissions determine which files can be returned.

Consequently, changing the path in one block cannot affect a request that is being handled by another block. A default page is often evidence of a hostname, address, port, activation or ordering problem rather than a bad filesystem path.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Read Apache’s actual virtual-host map first

Do not infer the active configuration from an editor window. Ask Apache to print the configuration it parsed:

apachectl -S

On systems that provide the httpd command, use:

httpd -S

The output identifies the address and port for each virtual host, the ServerName and aliases Apache recognized, which host is the default, and the source file and line where each definition came from. The Apache virtual-host documentation recommends this map specifically for debugging.

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

What to look for in the output

  • The intended site must appear on the same IP address and port used by the request.
  • The expected file must be the source of the block you edited. A similarly named file elsewhere can be the one Apache actually loaded.
  • The intended hostname and every alias you use must be listed.
  • A default server or first-listed entry that belongs to another site explains an unmatched request.
  • An address such as *:80 does not cover a request arriving on a different port or through a more-specific address match.

Save this output before making changes. After the fix, run the same command again and compare the selected address, names, order and source file.

Verify that the request reaches this server

A correct virtual-host file cannot help if the hostname resolves elsewhere. Resolve the exact hostname the browser uses and compare the result with the server address shown by apachectl -S or httpd -S. Check both the bare domain and any www name; they can point to different destinations.

For a local or pre-DNS test, create a temporary hosts-file entry that maps the hostname to the intended server IP. Then request that hostname, not an unrelated IP address. Apache’s hostname-based examples depend on either DNS or a hosts entry so that the name reaches the server.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Do not test with the wrong port

Record whether the client is using HTTP on port 80 or another port. A block declared as <VirtualHost *:80> cannot answer a request that arrives on a different port. Likewise, a request sent to a specific address may not enter a block declared only for a different address, even when the hostname text is correct. Confirm the destination address and port in the browser, test client, load balancer or reverse proxy.

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

Account for proxies and load balancers

If a proxy terminates the connection or forwards the request, inspect the hostname it sends in the Host header. The browser’s visible URL and Apache’s received hostname are not necessarily identical. A proxy that forwards an internal name, omits the expected host or sends traffic to another port can make Apache select the default vhost. Correct the proxy’s destination and host-header behavior before changing the web root.

Make hostname matching explicit

Every name-based virtual host should contain an explicit ServerName. Add each alternate name with ServerAlias; do not rely on a filename or on Apache guessing which domain you intended. A typo, missing alias or different spelling causes the request to fall through to the first matching block.

Use one block for the names that belong together

For a site that answers both the bare domain and its www form, declare both names in the same block:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example/public

    <Directory /var/www/example/public>
        Require all granted
        AllowOverride All
    </Directory>
</VirtualHost>

The path is absolute, and the <Directory> section names that same path. The official Apache examples use this core arrangement: a <VirtualHost> block containing ServerName and DocumentRoot. The first listed block for an address and port remains the fallback for names that match no ServerName or ServerAlias.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Check for subtle name differences

  • Compare the browser’s hostname character for character with ServerName and every ServerAlias.
  • Include both the bare name and www when both are intended to work.
  • Check for an old domain, an internal hostname or a spelling variant in bookmarks and proxy settings.
  • Ensure the vhost uses the port on which the name is actually received.

Confirm the intended site is enabled and ordered

On Debian and Ubuntu, the file in /etc/apache2/sites-available is not active merely because it exists. Confirm that the intended site is enabled with a2ensite and that its link appears in /etc/apache2/sites-enabled. Then inspect whether 000-default or another earlier vhost is catching requests that do not match your names.

After enabling a file, run apachectl -S or httpd -S again. The parsed map, not the directory listing, tells you whether Apache loaded the block and where it appears in the order.

Why order matters

Order is significant only after Apache has found the matching address and port and still cannot find a matching hostname. In that case the first listed block becomes the default. If a request uses an unlisted hostname, a default site may therefore serve its own DocumentRoot even though your intended block is present and valid.

Align DocumentRoot with directory access rules

Set DocumentRoot to the intended absolute directory, then update the corresponding <Directory> block. Apache warns that leaving permissions and options attached to the old path can produce an access error after the root changes.

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.
DocumentRoot /var/www/example/public

<Directory /var/www/example/public>
    Require all granted
    AllowOverride All
</Directory>

The two paths should describe the same directory. A mismatch can produce a forbidden response, prevent overrides from being read or leave rewrite behavior different from what you expect. It does not, however, explain another site’s distinctive files as well as a virtual-host selection error does; use the vhost map to distinguish those cases.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Check the filesystem path itself

  • Verify that the directory exists at the exact absolute path in the active block.
  • Place a temporary, distinctive index file in that directory so a successful response identifies the root unambiguously.
  • Remove or rename the marker after testing; it is a diagnostic aid, not a permanent page.
  • If Apache returns an access error after the path change, review the matching <Directory> rules rather than changing the vhost name again.

Test the configuration before reloading

Always run the configuration test appropriate to the installed command before asking Apache to reload:

apachectl configtest
apache2ctl configtest
httpd -t

Use the command supplied by your package; the names vary by distribution. Fix every syntax error reported by the test. A failed test should stop the reload so that a known-good running configuration remains in service.

Once the test succeeds, reload Apache using the service procedure documented for your distribution. Then request the exact hostname and port again. Re-run the vhost map if the response is still wrong; this confirms whether the new file was parsed and whether the selected block changed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use logs and a controlled response to prove the selected root

Inspect the access and error logs associated with the suspected vhost. The access log can show which hostname and URL arrived, while the error log can reveal a missing file, denied access or rewrite failure. If several sites share a server, make sure you are reading the logs configured for the block you think is active.

A distinctive temporary index file is the simplest visual test. You can also add a temporary response header in the selected vhost, provided your configuration already supports the module and directive you choose. Test one change at a time, record the result, and remove diagnostic markers afterward. The purpose is to identify the directory that answered, not to leave debugging content exposed.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Distribution layouts to recognize

Platform family Main configuration layout Virtual-host file location or pattern Activation detail
Debian/Ubuntu /etc/apache2/apache2.conf /etc/apache2/sites-available and /etc/apache2/sites-enabled Enable the intended site with a2ensite; inspect the resulting link and order.
Fedora/RHEL /etc/httpd/conf/httpd.conf /etc/httpd/conf.d Configuration files in the package’s included layout are parsed according to that distribution’s Apache setup.

These layouts and service commands can vary by release. Use the package documentation installed on the server when choosing the reload command, but use Apache’s own map and configuration test to verify the result.

Failure branches: match the symptom to the cause

The Apache default page appears

First run apachectl -S or httpd -S. If the default vhost is first for the request’s address and port, compare the requested hostname with the intended block’s ServerName and aliases. Then verify DNS or the hosts entry. A missing name match, wrong destination IP or wrong port is more likely than a broken DocumentRoot.

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

Another site’s files appear

Use a marker file in each candidate root and inspect the parsed map. The request is probably matching another block on the same address and port, or the proxy is sending a hostname that belongs to that site. Correct the exact name, alias, destination or port before editing filesystem paths.

The new root returns a forbidden or access error

Confirm that the active block really contains the new absolute path, then make its <Directory> path match. Apache’s warning about permissions and options on the old path is directly relevant here. Run the configuration test and inspect the vhost’s error log for the specific rule that denied the request.

The configuration file looks right but Apache ignores it

Check the source filename reported by -S. On Debian/Ubuntu, confirm the file is enabled and linked under sites-enabled. A correct file in sites-available that is not enabled is not part of the active configuration. Also check that you edited the file Apache reports, not a duplicate with a similar name.

Only one hostname fails

Compare the failing hostname with the block’s ServerName and ServerAlias values. Add the missing alias, correct the spelling and verify that DNS for that name reaches the same server. If the bare name works but www does not, they are not automatically interchangeable.

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

A repeatable repair checklist

  1. Run apachectl -S or httpd -S and record the selected address, port, names, default host and source files.
  2. Resolve the exact hostname and verify that it reaches the intended server IP.
  3. Confirm the request uses the address and port covered by the intended <VirtualHost> block.
  4. Put an explicit ServerName in the block and add every required alternate hostname with ServerAlias.
  5. On Debian/Ubuntu, enable the intended site and inspect /etc/apache2/sites-enabled for order and stale defaults.
  6. Set DocumentRoot to the intended absolute directory and make the matching <Directory> path identical.
  7. Run apachectl configtest, apache2ctl configtest or httpd -t, depending on the installed command.
  8. Reload Apache using the local package’s documented service procedure.
  9. Request the exact hostname again, using a distinctive temporary file or response marker to identify the answering root.
  10. Review the relevant access and error logs, remove temporary markers and repeat the vhost map check if the result is still unexpected.

Preventing the same mistake on the next site

Create each name-based vhost with an explicit ServerName, complete aliases, a clearly named absolute DocumentRoot and a matching <Directory> section. Keep a record of which address and port the site uses. After every change, run the configuration test and inspect the parsed vhost map before reloading. When adding a new domain, verify DNS and test the exact hostname rather than relying on an IP-only request. These habits prevent Apache’s fallback-to-first-vhost behavior from being mistaken for a directory failure.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair 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.