Apache Default Virtual Host Configuration
Learn where Ubuntu stores Apache's default virtual host, how its directives work, how to customize it safely, and how to prepare for multiple websites.
Apache HTTP Server is web server software that receives HTTP requests and serves web content. On Ubuntu and other Debian-based systems, Apache commonly serves a single website through a virtual host: a configuration block that defines how Apache handles a particular website, address, port, or hostname.
A default virtual host is the fallback virtual host. Apache uses it when a request does not match a more specific enabled virtual host. This makes it useful for a server hosting one website, a local test page, or a first site before additional domains are configured.
You can retain the default site, customize it when it is intended to remain the primary site, or copy its structure into a separate configuration file for another website. Do not overwrite an existing site's configuration merely to add a second site.
Where the default site configuration is stored
On Ubuntu and Debian-based systems, the standard default site definition is:
/etc/apache2/sites-available/000-default.conf
The sites-available directory stores site definitions that are available for use. The sites-enabled directory contains references to the site definitions that Apache should load. A file existing in sites-available is not necessarily active; the site must be enabled before Apache loads its virtual host configuration.
| Path | Role | Typical contents | When to modify |
|---|---|---|---|
/etc/apache2/sites-available | Stores available site configurations. | Files such as 000-default.conf and custom site files. | Edit or create a definition before enabling it. |
/etc/apache2/sites-enabled | Contains enabled site configuration references loaded by Apache. | Usually symbolic links to files in sites-available. | Usually manage it with a2ensite and a2dissite, rather than editing links manually. |
/var/www/html | Standard default document root in this setup. | HTML, CSS, JavaScript, images, and other web content. | Place or replace files served by the default site. |
${APACHE_LOG_DIR} | Apache configuration variable for the log directory. | On Ubuntu, it normally resolves under /var/log/apache2. | Use it in site configurations when selecting log destinations. |
To inspect the available and enabled definitions, you can list both directories:
ls -l /etc/apache2/sites-available
ls -l /etc/apache2/sites-enabled
For background on the two directory roles, see Apache sites-available and Apache sites-enabled.
Understanding the VirtualHost block
A virtual host is enclosed by an opening <VirtualHost> directive and a matching closing </VirtualHost> directive. Every directive that belongs to that site goes inside the block.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The value *:80 has two parts. The asterisk is a wildcard address, meaning Apache accepts requests on all local IP addresses associated with that port. Port 80 is the conventional TCP port for unencrypted HTTP traffic. Therefore, this block applies to HTTP requests received on port 80 for any local address, subject to virtual-host matching rules.
For a single-site server, this block commonly handles requests that do not match another enabled virtual host. When several virtual hosts are enabled, Apache can use address, port, and hostname information to select a more specific configuration.
Core directives in the default configuration
| Directive | Example value | Purpose | Operational effect |
|---|---|---|---|
VirtualHost | *:80 | Container identifying the address and port for the site. | Applies the enclosed settings to HTTP requests received on all local addresses at port 80. |
ServerAdmin | webmaster@localhost | Administrative contact address. | May appear in server-generated error pages or related error reporting. |
DocumentRoot | /var/www/html | Directory containing files Apache may serve. | Maps requests for the site to files below the specified directory. |
ErrorLog | ${APACHE_LOG_DIR}/error.log | Destination for site error messages. | Records configuration, permission, application, and request-processing errors. |
CustomLog | ${APACHE_LOG_DIR}/access.log combined | Destination and format for request logs. | Records requests and response details using the combined log format. |
ServerAdmin
ServerAdmin identifies the administrator contact address associated with the virtual host. Apache can include this address in server-generated error pages. Replace the example value with an appropriate address if the site will be used beyond local testing.
DocumentRoot
DocumentRoot is the filesystem directory from which Apache serves website files. In the standard default setup, it is /var/www/html. A request for http://localhost/ may therefore resolve to an index file in that directory, such as /var/www/html/index.html.
ErrorLog and CustomLog
ErrorLog records problems associated with the virtual host. It is especially useful for diagnosing server errors, permission failures, invalid configuration, and access denials.
CustomLog records incoming HTTP requests. The word combined selects a common access-log format containing request information, response status, transferred bytes, referrer information, and user-agent information. Ubuntu configurations use APACHE_LOG_DIR as a variable representing the Apache log directory.
For a broader explanation of request and error records, see Apache access and error log files.
The default document root and test page
The standard document root is /var/www/html. Content placed there can be served by the default virtual host. A simple local homepage can be created with:
echo '<h1>My Apache site</h1>' | sudo tee /var/www/html/index.html
Ubuntu's Apache package may also provide an example HTML page in this directory. That distribution-provided page is a basic confirmation that Apache is running and serving the expected document root; it is not a complete application or production website.
Request the site locally through HTTP:
http://localhost/
You can also test from a terminal with:
curl http://localhost/
localhost is a hostname that refers to the current machine. If the page displays, Apache is responding on port 80 and is serving content from the selected virtual host's document root.
Safe customization workflow
Customize the default site when it remains the primary site
If this server will host only one website, editing /etc/apache2/sites-available/000-default.conf can be appropriate. For example, you might change DocumentRoot from /var/www/html to another directory. Ensure that the directory exists and that Apache can traverse and read it.
sudoedit /etc/apache2/sites-available/000-default.conf
After editing, always test the configuration before applying it:
sudo apache2ctl configtest
A successful test normally reports Syntax OK. Only after that should you reload Apache:
sudo systemctl reload apache2
A reload makes valid configuration changes take effect without unnecessarily stopping the running service. If the syntax test fails, correct the reported problem before attempting to reload.
Create a separate file for another website
When adding a second website, create a separate virtual host file rather than replacing the configuration of the existing site. A separate file allows each site to have its own document root and log destinations.
sudoedit /etc/apache2/sites-available/example-site.conf
A basic hostname-based site might look like this:
<VirtualHost *:80>
ServerName example.test
ServerAlias www.example.test
DocumentRoot /var/www/example-site
ErrorLog ${APACHE_LOG_DIR}/example-site-error.log
CustomLog ${APACHE_LOG_DIR}/example-site-access.log combined
</VirtualHost>
ServerName is the primary hostname for the site. ServerAlias adds other hostnames that should select the same virtual host. Explicitly setting ServerName for additional sites avoids ambiguous host matching and makes the intended selection clear.
Enable the new site, validate the complete Apache configuration, and reload:
sudo a2ensite example-site.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
Each additional website normally receives its own VirtualHost block and configuration file. Its DocumentRoot and log files can be distinct from those of the default site. Name-based matching uses the requested hostname, including the HTTP Host header, together with the address and port.
See creating a new Apache virtual host for the next step in a multi-site setup.
How Apache chooses the default virtual host
Apache first considers the address and port on which the request arrived. If multiple enabled virtual hosts share that address and port, Apache compares the requested hostname with ServerName and ServerAlias. If no more specific hostname match is found, Apache uses the default virtual host for that address and port.
The default site is therefore a fallback, not necessarily a site that has a special domain name. A request made directly to an IP address, an unknown hostname, or a hostname that has no matching enabled definition may be handled by the default virtual host.
Troubleshooting
Unexpected page at localhost
If the browser does not show the expected homepage at http://localhost/, check whether Apache is running, whether the enabled virtual host points to the intended DocumentRoot, and whether that directory contains an index file.
sudo systemctl status apache2
ls -l /var/www/html
sudo tail -f /var/log/apache2/access.log
sudo tail -f /var/log/apache2/error.log
Common causes include an inactive Apache service, an empty document root, a changed configuration that was not reloaded, or another virtual host handling the request.
Apache refuses to reload
Malformed VirtualHost syntax, a missing closing tag, a directive without its required argument, an invalid path, or an unsupported directive can prevent a reload. Run:
sudo apache2ctl configtest
Read the reported file and line number, correct the configuration, run the test again, and reload only after the result is valid.
403 Forbidden after changing DocumentRoot
A 403 response commonly means Apache cannot traverse or read the new directory, or that Apache's directory authorization policy does not permit access. Check filesystem ownership and permissions, review applicable Directory authorization settings, and read the error log for the specific denial reason.
New site configuration has no effect
Confirm that the file is enabled in sites-enabled, that Apache was reloaded after validation, and that the requested hostname matches the new site's ServerName or ServerAlias. A file that exists only in sites-available is not active.
Exam-relevant notes
/etc/apache2/sites-available/000-default.confis the standard Ubuntu/Debian default site definition.sites-availablestores available definitions;sites-enabledcontains enabled configuration references loaded by Apache.DocumentRootidentifies the directory from which site files are served.<VirtualHost *:80>means all local addresses on the conventional HTTP port.- Use
sudo apache2ctl configtestbefore reloading a changed configuration. - Use
sudo systemctl reload apache2after a successful test. - Additional sites should normally have separate files, document roots, logs, and explicit
ServerNamevalues.
To continue, review installing Apache on Ubuntu, Apache's ports configuration, and configuring SSL for HTTPS virtual hosts.