Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk9 min

How to Set Up Apache Virtual Hosts on Ubuntu

A practical guide to creating, enabling, testing, and troubleshooting Apache virtual hosts on Ubuntu, including DNS, fallback behavior, and HTTPS.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache virtual hosts let one Ubuntu server deliver different websites from a single IP address. You define each hostname and its document directory in /etc/apache2/sites-available, enable the corresponding site, reload Apache, and point DNS at the server. Apache then chooses the site by matching the hostname in each request.

This guide covers a complete HTTP setup, local testing before DNS changes, the reason the default Apache page sometimes appears, and the extra configuration required for HTTPS.

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.

What an Apache virtual host does

A virtual host is a named Apache configuration for one website. A typical block tells Apache three things: which hostname to recognize, which additional names should reach the same site, and which directory contains the files to serve.

With name-based virtual hosting, several domains share one server address. DNS sends each domain to that address; the browser includes the requested hostname in its HTTP request; Apache compares that name with ServerName and ServerAlias, then serves the matching DocumentRoot. Name-based hosting is usually simpler than assigning a separate IP address to every site.

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

How Apache chooses a site

Apache first groups virtual hosts by the most specific local address and port, such as *:80 for ordinary HTTP. Within that group it compares the request hostname against each ServerName and ServerAlias. If no name matches, Apache sends the request to the first virtual host listed for that address and port.

That fallback rule explains the familiar Apache default page: the request reached your server, but the hostname did not match the intended site, or the default file appears first in the parsed configuration. The command sudo apachectl -S shows the order Apache actually uses, rather than the order you assume from filenames.

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

Before you begin

  • An Ubuntu server with administrative access through sudo.
  • A hostname you want to serve, such as example.com, and any aliases such as www.example.com.
  • A planned document directory, for example /var/www/example.com.
  • Port 80 reachable for HTTP testing. HTTPS will use a separate port-443 virtual host later.

Decide whether the site should be publicly reachable immediately. Public access requires DNS records that resolve the hostname to the server address. A temporary hosts-file override is useful for testing from one computer, but it does not publish the name for anyone else.

Install Apache and confirm the service

If Apache is not installed, install the Ubuntu package and start the service:

sudo apt update
sudo apt install apache2
sudo systemctl enable --now apache2

Check that the service is running:

sudo systemctl status apache2

On a new installation, browsing to the server address normally displays Ubuntu’s Apache default page. That confirms the web server is responding, but it does not yet confirm that your own virtual host is selected.

Create a separate directory for the site

Keep each website in its own document root. Create the directory and a small index file so that a successful test is unmistakable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
sudo mkdir -p /var/www/example.com
sudo sh -c 'printf "%sn" "Example.com virtual host is working" > /var/www/example.com/index.html'

The directory name is your choice; it does not have to match the domain, but using the domain makes a multi-site server easier to maintain. The path in this command must exactly match the DocumentRoot value you will place in the configuration.

Write the virtual-host file

Ubuntu keeps available site definitions in /etc/apache2/sites-available. Create a file named after the hostname:

sudo nano /etc/apache2/sites-available/example.com.conf

Put this block in the file:

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

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>

What each directive means

  • <VirtualHost *:80> places the site in the HTTP virtual-host group on port 80. The asterisk means Apache accepts the site on the server’s available addresses.
  • ServerName example.com is the primary hostname Apache should match.
  • ServerAlias www.example.com adds another name for the same content. Add every additional hostname you intend to use; an omitted alias will not match.
  • DocumentRoot /var/www/example.com identifies the directory Apache serves.
  • ErrorLog and CustomLog give this site separate error and access logs under Apache’s log directory.

Save the file exactly as shown, including the closing </VirtualHost> line. A misspelled directive, hostname, or path can prevent the intended site from loading.

Enable the site and decide what to do with the default host

Creating a file in sites-available does not activate it. Enable the definition with:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo a2ensite example.com.conf

For a controlled test, you can disable Ubuntu’s default site:

sudo a2dissite 000-default.conf

Disabling the default host is not mandatory. It can be useful while diagnosing an individual site, but a deliberate fallback virtual host is often preferable on a production server so unmatched requests receive a controlled response instead of an unintended website.

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

Validate Apache’s parsed configuration

Check the syntax before reloading:

sudo apachectl configtest

A successful result should report Syntax OK. If Apache reports an error, correct the referenced file and line before continuing.

Next, inspect the complete virtual-host map:

sudo apachectl -S

This output shows which files define each address-and-port group, the first host in each group, and the names Apache has associated with every virtual host. Use it to catch duplicate names, a misspelled ServerName, a missing alias, or an unexpected default file listed before your site.

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

Reload Apache after the configuration change

Apply a valid configuration with a reload:

sudo systemctl reload apache2

A reload makes Apache read the updated definitions while avoiding the full stop-and-start cycle of a restart. If a reload fails or the service is in a bad state, use:

sudo systemctl restart apache2

Restarting is more disruptive because the service is fully restarted, so use reload for routine virtual-host edits and reserve restart for cases where reload is insufficient.

Point DNS to the server

Apache cannot make a public hostname resolve. At your DNS provider, create the appropriate A record for an IPv4 address and/or AAAA record for an IPv6 address, pointing the hostname to the server’s address. The exact DNS interface and propagation behavior depend on the provider.

The hostname must resolve to this server before visitors elsewhere can reach the virtual host. If DNS still points to an old server, Apache on the new server will never receive the request, regardless of how correct its configuration is.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Test locally before changing public DNS

For a test from one client computer, add a temporary hosts-file entry mapping the hostname to the server address. The file location depends on the client operating system. On Ubuntu and other Linux systems it is /etc/hosts; on Windows it is under the system directory’s hosts file.

A hosts-file entry affects only the machine where it is stored. It is therefore suitable for checking the page, logs, and routing before public DNS changes, but it is not a substitute for an A or AAAA record.

Verify that the intended host is being served

Test with the exact hostname, not only the numeric IP address. A browser request to the IP may select the first virtual host because it does not provide a matching name.

From a client that resolves the name correctly, open http://example.com and, if configured, http://www.example.com. Confirm that both names display the test file from /var/www/example.com.

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

You can also make an explicit HTTP request from the server or another Linux client:

curl -H 'Host: example.com' http://SERVER_IP/

Replace SERVER_IP with the server address. Supplying the Host header tests Apache’s name matching even when public DNS has not changed. To test the alias, substitute www.example.com in the header.

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

Why you still see the Apache default page

The default page is a routing symptom, not proof that the site file was ignored. Work through these checks in order:

  1. Confirm the requested hostname. Make sure the browser address, curl Host header, and ServerName use the same spelling. A request for a name that is not listed will fall back to the first host.
  2. Check aliases. If you configured only example.com but visit www.example.com, add the latter as a ServerAlias and reload Apache.
  3. Inspect the parsed order. Run sudo apachectl -S. Verify that the intended file appears in the *:80 group and note which host is first.
  4. Confirm the site is enabled. Run sudo a2ensite example.com.conf, then reload. Editing a file that remains only in sites-available has no effect.
  5. Check DNS or the hosts override. If the hostname resolves to another address, your request is reaching a different machine. For a local test, verify the temporary hosts-file line points to this server.
  6. Check the document root. Ensure /var/www/example.com exists and contains the expected index file. A correct hostname with an incorrect path cannot display the intended content.

Adding a second or third website

Repeat the same pattern for every domain, using a different directory and configuration file. For a second site:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo mkdir -p /var/www/second.example
sudo sh -c 'printf "%sn" "Second site is working" > /var/www/second.example/index.html'
sudo nano /etc/apache2/sites-available/second.example.conf

Use a separate block:

<VirtualHost *:80>
    ServerName second.example
    DocumentRoot /var/www/second.example

    ErrorLog ${APACHE_LOG_DIR}/second.example-error.log
    CustomLog ${APACHE_LOG_DIR}/second.example-access.log combined
</VirtualHost>

Enable it, validate the map, and reload:

sudo a2ensite second.example.conf
sudo apachectl configtest
sudo apachectl -S
sudo systemctl reload apache2

Give each site a distinct ServerName, document root, and log filename. DNS for each public hostname must point to the same server address, while Apache separates the requests by hostname.

Name-based versus IP-based virtual hosting

Approach Addressing model Operational implication
Name-based Multiple hostnames share one IP address; Apache matches the hostname in the request. Usually simpler because DNS can map several names to one address.
IP-based Each virtual host uses a separate IP address. Requires additional addresses and a configuration organized around those addresses.

This guide uses name-based hosting because it is the normal choice when several websites share one Ubuntu server address.

HTTP and HTTPS virtual hosts

HTTPS is a separate listener and configuration. Create or enable a virtual host for port 443 and add the certificate and private-key paths supplied by your certificate issuer. The HTTP block on port 80 does not automatically provide encrypted service.

When a browser starts TLS, it can send the requested hostname through Server Name Indication (SNI). Apache uses that hostname to select the appropriate SSL virtual host, allowing multiple HTTPS sites to share an address when their certificates and port-443 definitions are correctly configured.

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.

A conceptual HTTPS block has the same naming and document-root directives as the HTTP block, plus certificate settings:

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

    SSLEngine on
    SSLCertificateFile /path/from/certificate-issuer/certificate.pem
    SSLCertificateKeyFile /path/from/certificate-issuer/private-key.pem

    ErrorLog ${APACHE_LOG_DIR}/example.com-ssl-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-ssl-access.log combined
</VirtualHost>

The certificate authority determines how certificates are issued and renewed; those steps vary by issuer and are outside the basic virtual-host procedure. Do not copy the example paths literally: replace them with the paths provided for your certificate.

Useful comparison of common choices

Choice What it changes When to use it
Reload Applies the new configuration without a full service restart. Routine virtual-host edits after a successful syntax check.
Restart Stops and starts Apache completely. When a reload is insufficient or the service needs a full restart.
Public DNS Makes the hostname resolve for users on the internet. After the server configuration is ready for public access.
Hosts-file override Changes name resolution only on one client machine. Private pre-DNS testing.
HTTP on port 80 Provides basic name-based routing without certificates. Initial setup and connectivity checks.
HTTPS on port 443 Adds TLS certificates and SNI-aware SSL virtual-host selection. Encrypted production traffic.

Final deployment checklist

  • Apache is installed and its service is running.
  • Each site has a separate directory and a recognizable index file.
  • The configuration file is under /etc/apache2/sites-available.
  • ServerName, every required ServerAlias, and DocumentRoot are spelled correctly.
  • The site is enabled with a2ensite.
  • sudo apachectl configtest reports a valid configuration.
  • sudo apachectl -S shows the expected names and fallback order.
  • Apache has been reloaded after the change.
  • DNS A/AAAA records point the public names to this server, or a temporary hosts-file entry is in place for local testing.
  • HTTPS has its own port-443 block and issuer-provided certificate paths.

Once those checks pass, Apache can host multiple domains on one Ubuntu server while keeping each site’s files, logs, and hostname mapping separate.

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.

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.

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