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 Multiple Websites on One Apache Server

A practical Apache guide to hosting several domains on one server, covering DNS, virtual-host configuration, HTTPS certificates, reverse proxies, fallback behavior, and diagnostics.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Host multiple domains on one Apache machine with name-based virtual hosts. Point every domain to the server with DNS, give each site its own <VirtualHost> block, test Apache’s parsed configuration, and then add matching HTTPS blocks. Apache uses the HTTP Host header—or TLS SNI for HTTPS—to choose the site.

What Apache uses to choose a website

A browser first resolves a domain name to an IP address. It then sends the hostname in the HTTP Host header. Apache compares that hostname with the ServerName and ServerAlias values in virtual hosts listening on the requested address and port. The selected block supplies the site’s files, logs, proxy rules, and other settings.

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.

This is called name-based virtual hosting. It lets many domains share one IPv4 or IPv6 address. Apache’s documentation requires DNS to point the names at the server and configuration to recognize those names; one step cannot substitute for the other.

For HTTPS, the client sends the hostname during the TLS handshake as Server Name Indication (SNI). Apache uses SNI to select the certificate-backed virtual host, then applies the request hostname to the HTTPS configuration. A certificate must cover every name that block serves.

#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.

Plan the layout before editing Apache

Choose names and aliases

Decide the canonical hostname for each site, normally an apex name such as example.com or a subdomain such as app.example.com. List alternate names—commonly the www form—in ServerAlias. Keep each hostname assigned to one intended site; duplicate names make troubleshooting and fallback behavior unpredictable.

Create separate document roots

Give every static site a directory that is not shared accidentally with another site. A predictable layout is:

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

Place each site’s index file and application assets in its own public directory. The Apache worker must be able to traverse the parent directories and read the files. Keep writable upload or cache directories separate and grant them only the write access they require.

Separate the logs

Use a distinct access log and error log for each virtual host. When a request displays the wrong site, the log that receives it identifies which block Apache selected and records errors without mixing unrelated domains.

Make DNS point every domain to the server

For each hostname, create the necessary DNS records at the authoritative DNS service:

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
  • An A record for an IPv4 address.
  • An AAAA record when the server accepts IPv6 traffic.
  • Records for aliases such as www.example.com, either pointing directly to the address or using a CNAME where appropriate.

Check both A and AAAA records. A stale AAAA record can send IPv6 clients to a different machine even when the A record is correct. DNS changes are controlled by the record’s TTL and resolver caches; do not diagnose Apache until the names resolve to the intended host from the networks where visitors will connect.

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.

DNS does not create an Apache site. Conversely, an Apache ServerName does not publish a domain that has no DNS record.

Configure HTTP virtual hosts

Create one port-80 block per site. Each block should explicitly state ServerName, a site-specific DocumentRoot, and any aliases. The Directory section grants access to that root; its path must exactly match the document root.

&lt;VirtualHost *:80&gt;
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    ErrorLog /var/log/apache2/example.com-error.log
    CustomLog /var/log/apache2/example.com-access.log combined

    &lt;Directory /var/www/example.com/public&gt;
        Require all granted
        AllowOverride All
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
    ServerName example.org
    ServerAlias www.example.org
    DocumentRoot /var/www/example.org/public
    ErrorLog /var/log/apache2/example.org-error.log
    CustomLog /var/log/apache2/example.org-access.log combined

    &lt;Directory /var/www/example.org/public&gt;
        Require all granted
        AllowOverride All
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;

AllowOverride All permits directives in a site’s .htaccess files. If you do not need per-directory overrides, use a narrower setting or disable overrides and place the required rules in the virtual-host configuration. Broad overrides increase the amount of configuration Apache must inspect and can permit rules you did not intend to enable.

Enable the files on Debian-family systems

Debian and Ubuntu installations commonly keep site definitions in /etc/apache2/sites-available/ and create enabled links in /etc/apache2/sites-enabled/. A typical sequence is:

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)
  1. Create files such as /etc/apache2/sites-available/example.com.conf and example.org.conf.
  2. Enable them with sudo a2ensite example.com.conf example.org.conf. The helper’s exact behavior depends on the installed distribution.
  3. Check syntax with sudo apachectl configtest. Continue only when it reports Syntax OK.
  4. Reload Apache without dropping existing connections: sudo systemctl reload apache2.

Other operating systems may include configuration files from a main httpd.conf or a distribution-specific directory instead of providing a2ensite. Use that system’s documented include mechanism; do not copy Debian paths or service names blindly.

Verify the HTTP sites before adding TLS

Test each canonical name and alias explicitly. A browser may retain redirects or cached responses, so command-line requests are useful:

curl -i http://example.com/
curl -i http://www.example.com/
curl -i http://example.org/

Confirm that each response contains the expected site content and that each hostname writes to its own access log. If you are testing before public DNS is available, resolve the name to the server’s address for the test client rather than changing Apache’s matching rules.

Inspect Apache’s view of the configuration with:

sudo apachectl -S

On Windows, the corresponding command is:

httpd.exe -S

The output lists listening addresses and ports, recognized names, the file that defined each block, and the order Apache will use. This is more reliable than reading files in directory order because include files, generated links, and distribution defaults can alter the effective configuration.

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

Add HTTPS virtual hosts

After HTTP routing works, obtain certificates for the names each site serves and configure matching port-443 blocks. Certificate issuance, renewal, and private-key storage vary by certificate authority and operating system, so follow the authority’s current procedure and protect private keys from unprivileged users.

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

A minimal static-site HTTPS block has the same identity and document root as its HTTP counterpart, plus TLS settings:

&lt;IfModule mod_ssl.c&gt;
&lt;VirtualHost *:443&gt;
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public
    ErrorLog /var/log/apache2/example.com-ssl-error.log
    CustomLog /var/log/apache2/example.com-ssl-access.log combined

    SSLEngine on
    SSLCertificateFile /etc/ssl/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/ssl/example.com/privkey.pem

    &lt;Directory /var/www/example.com/public&gt;
        Require all granted
        AllowOverride All
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;
&lt;/IfModule&gt;

Use certificate and key paths that actually exist on your system, and ensure the certificate includes both the apex and alias names if both are listed. A certificate covering several names can serve one virtual host; separate certificates are also valid when each HTTPS block has the correct certificate.

Redirect HTTP only after HTTPS works

Once the certificate-backed port-443 block serves the correct site, change that site’s port-80 block into a redirect or add a redirect rule. Test the HTTPS URL directly first. Redirecting too early can hide a certificate, SNI, or port-443 routing error behind a loop or a browser warning.

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

Keep the redirect scoped to the intended host. A catch-all rule that redirects every unknown hostname can make diagnosing a wrong default virtual host harder.

Use Apache as a reverse proxy for application sites

If the site is served by an application process rather than files in a document root, use a proxy virtual host. Apache receives the public request and forwards it to a local backend such as a process listening on port 3000.

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.
&lt;VirtualHost *:80&gt;
    ServerName app.example.com
    ErrorLog /var/log/apache2/app.example.com-error.log
    CustomLog /var/log/apache2/app.example.com-access.log combined

    ProxyPreserveHost On
    ProxyPass        / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
&lt;/VirtualHost&gt;

ProxyPreserveHost On passes the original hostname to the backend, which matters for applications that generate absolute URLs, select a tenant, or enforce host-based security. ProxyPass forwards the request path; ProxyPassReverse rewrites redirect headers returned by the backend so clients continue to use the public hostname.

Enable only the proxy modules required by the backend and protocol you use. Restrict forwarding to explicitly configured destinations. An unrestricted forward proxy can let outsiders relay traffic through your server, abuse your bandwidth, or reach internal services.

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

For HTTPS application sites, create the same proxy rules inside a certificate-backed *:443 virtual host. Decide whether the backend receives HTTP or HTTPS on the private connection, and configure the application to trust forwarded scheme and client-IP headers only when they are set by your Apache instance.

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

Understand the default-site fallback

If the request address and port match a set of virtual hosts but the hostname matches none of their ServerName or ServerAlias values, Apache uses the first listed virtual host for that address and port. This is why an unknown domain can display an unrelated site.

Make the fallback intentional. Put a simple default site first, or define a deliberate catch-all that returns an error instead of exposing a customer site. Do not rely on the machine’s hostname or on whichever distribution file happens to be included first. Review the effective order with apachectl -S after every include or enablement change.

Diagnose the common failure modes

Symptom Likely cause What to check
Every domain shows one site The names do not reach the intended server, or the virtual hosts do not contain unique names. Check A and AAAA records, then run apachectl -S and verify every ServerName and ServerAlias.
An unknown hostname shows the first site Apache’s documented fallback is the first matching block. Choose an intentional default and place it first for that address and port.
The alias does not work The alias is absent, misspelled, or not present in DNS. Add the exact name to ServerAlias, create its DNS record, and test it separately.
HTTPS shows the wrong certificate The port-443 blocks or certificate names do not match the SNI hostname. Confirm the hostname appears in the certificate, that the HTTPS block has the correct ServerName, and that apachectl -S shows the expected order.
HTTP works but HTTPS fails to connect Apache is not listening on 443, a firewall blocks it, or the TLS module/configuration is unavailable. Check the listen configuration, service logs, firewall rules, and the result of apachectl configtest.
Apache will not reload A syntax error, missing file, duplicate directive, or invalid module reference prevents the new configuration. Run apachectl configtest; fix the reported file and line before reloading.
A proxy returns 502 or times out The backend is stopped, listening on another address or port, or inaccessible to Apache. Verify the process is listening on the address in ProxyPass, inspect the proxy error log, and test the backend locally.
Files return 403 The directory permissions, parent-directory traversal, or Require rule prevents access. Check the complete path permissions and the matching Directory section; avoid making the entire filesystem writable.

Choose the right hosting arrangement

Arrangement When it fits Trade-offs
Name-based virtual hosting Several domains can share one server address. Simple and economical, but all sites share the machine’s resources and failure domain.
IP-based virtual hosting A site or protocol genuinely requires a separate address. Provides address-level separation but requires additional IP addresses and more network planning.
Static DocumentRoot Apache serves files directly. Fewer moving parts; application runtimes, process supervision, and deployments are your responsibility if dynamic behavior is needed.
Reverse proxy to an application Each site is backed by a separate process, framework, or container. Supports process isolation and independent runtimes, but adds proxy, health, logging, and timeout configuration.
One certificate per hostname Sites have independent certificate lifecycles. Compartmentalizes renewal, while increasing the number of certificates to monitor.
One certificate covering several names A set of aliases is managed together. Fewer certificates, but adding or removing a name can require reissuing the shared certificate.
One shared server Traffic is moderate and centralized administration is desirable. Lower operational overhead, but a host failure or resource spike can affect every site.
Separate VPS instances Sites need stronger isolation, independent maintenance windows, or distinct resource guarantees. Higher cost and administration, with separate patching, monitoring, and TLS work.

Apache’s virtual-host routing rules do not establish a universal limit on the number of domains or visitors one machine can handle. Capacity depends on CPU, memory, storage, network traffic, TLS workload, application behavior, and configuration. Measure the workloads you actually run rather than applying a fixed site-count promise.

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

Operate several sites safely

  • Keep each site’s configuration, logs, deployments, and writable data clearly separated.
  • Run apachectl configtest before every reload and retain the previous known-good configuration for rollback.
  • Use apachectl -S after adding or renaming a site to verify the parsed names and order.
  • Monitor each access and error log independently so a single failing application does not disappear in a shared log.
  • Renew certificates before expiry and verify that renewal updates the certificate path used by the active HTTPS block.
  • Limit proxy destinations, backend privileges, and filesystem write permissions.
  • Test apex and alias names over both HTTP and HTTPS after DNS, configuration, certificate, or firewall changes.

A repeatable deployment checklist

  1. Record every canonical hostname and alias, and decide whether the site is static or proxied.
  2. Create A and, where needed, AAAA records for each name; confirm they resolve to this server.
  3. Create a separate document root or backend process and establish the required permissions.
  4. Write one explicit port-80 virtual host per site with unique names, paths, and logs.
  5. Enable the configuration using the mechanism supplied by the operating system.
  6. Run apachectl configtest, correct every error, and reload Apache.
  7. Run apachectl -S and check address, port, names, source files, and order.
  8. Request every hostname over HTTP and verify content and per-site logs.
  9. Install certificates that cover the exact HTTPS names, then create matching port-443 blocks.
  10. Test HTTPS directly, including certificate identity and application behavior, before adding HTTP-to-HTTPS redirects.
  11. Define an intentional default for unknown names and document how to roll back the change.

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
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.