VMware ESXi and vSphere Cluster Management

Apache /etc/apache2/sites-available Directory

Learn how Debian and Ubuntu Apache use sites-available and sites-enabled for virtual hosts, including a2ensite, a2dissite, validation, reloads, and troubleshooting.

On Debian- and Ubuntu-based systems, /etc/apache2/sites-available is the main storage directory for Apache virtual host configuration files. These files describe websites that Apache could serve, but a file being present in this directory does not automatically make the site active.

Apache normally loads the site configurations exposed through /etc/apache2/sites-enabled. That directory contains symbolic links to selected files in sites-available. This separation lets an administrator keep configurations available without loading every one of them.

What Is a Virtual Host?

A virtual host is an Apache configuration that serves a distinct website or defines distinct behavior for a site. One Apache installation can serve multiple virtual hosts, often using different domain names such as example.com and shop.example.com.

Each virtual host can have its own domain names, document root, access rules, log files, redirects, authentication, and application settings. A virtual host configuration file is the set of Apache instructions that connects a hostname and request-handling rules to the website's files and features.

The Relationship Between Available and Enabled Sites

PathPurposeContainsEffect on Active Apache Configuration
/etc/apache2/sites-availableStores available virtual host definitions.Configuration files such as 000-default.conf and custom .conf files.Does not activate a site by itself.
/etc/apache2/sites-enabledIdentifies virtual hosts selected for loading.Symbolic links pointing to files in sites-available.Apache loads successfully enabled configurations from this directory.
/etc/apache2/ports.confDefines ports on which Apache listens.Listen directives, such as Listen 80.Controls whether Apache accepts connections on the ports used by virtual hosts.

A symbolic link is a filesystem reference to another path. For example, a link in sites-enabled can point to /etc/apache2/sites-available/example-site.conf. Enabling or disabling a site normally changes this link rather than moving or deleting the original configuration.

What a Virtual Host File Contains

Most site files contain a <VirtualHost> block. The opening tag identifies the address and port to which the block applies, and the closing tag marks the end of the virtual host configuration.

DirectivePurposeTypical Value or Use
<VirtualHost>Groups settings for one virtual host and associates them with an address and port.<VirtualHost *:80>
ServerNameSets the primary hostname for the site.ServerName example.com
ServerAliasAdds other hostnames or hostname patterns handled by the same site.ServerAlias www.example.com
DocumentRootSpecifies the filesystem directory containing the site's web content.DocumentRoot /var/www/example-site
<Directory>Controls permissions and options for a filesystem directory.Require all granted inside a matching directory block.
ErrorLogSpecifies where errors for the virtual host are recorded.${APACHE_LOG_DIR}/example-site-error.log
CustomLogSpecifies where access requests are recorded.${APACHE_LOG_DIR}/example-site-access.log combined

DocumentRoot is a filesystem path, not a URL. If it is set to /var/www/example-site, Apache looks there for requested content. A matching <Directory> block defines whether Apache may access that path and which directory features are allowed.

Example Virtual Host

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

    <Directory /var/www/example-site>
        Require all granted
    </Directory>

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

Save a configuration like this as /etc/apache2/sites-available/example-site.conf. The directory named by DocumentRoot must exist, and Apache's service account must be able to read the site's files.

The Default Apache Site

000-default.conf is the usual default virtual host file on Debian-derived Apache installations. Its basic configuration commonly resembles the following:

<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

The standard default document root is commonly /var/www/html. When a request does not match a more specific enabled virtual host, the default virtual host for the relevant address and port can handle it. The exact result also depends on the enabled virtual host order and the requested hostname.

Administrators may modify the default site, replace it with another default, or disable it when a different virtual host should handle requests. Disabling it does not delete 000-default.conf; the file remains available for later reuse.

Enabling a Site

Use a2ensite to enable a virtual host on Debian- and Ubuntu-style Apache installations. The command creates the appropriate symbolic link in sites-enabled.

sudo a2ensite example-site.conf
ls -l /etc/apache2/sites-enabled/
sudo apache2ctl configtest
sudo systemctl reload apache2

The configuration test should report Syntax OK before Apache is reloaded. A reload applies valid configuration changes without normally stopping the service or terminating established connections in the same way as a full restart.

Disabling a Site

Use a2dissite to remove the enabled-site link. The original configuration remains in sites-available.

sudo a2dissite example-site.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Disabling a site affects Apache only after the configuration is successfully reloaded. Do not delete the file from sites-available merely because you want to stop serving it temporarily.

Complete Site Configuration Workflow

  1. Create or edit a virtual host file in /etc/apache2/sites-available.
  2. Set the hostname, port, document root, directory access rules, and logging directives.
  3. Enable the file with a2ensite.
  4. Confirm that a symbolic link appears in /etc/apache2/sites-enabled.
  5. Run sudo apache2ctl configtest.
  6. Reload Apache with sudo systemctl reload apache2.

Apache only serves the site after its enabled configuration has been loaded successfully. A file that exists only in sites-available is a stored definition, not an active site.

Ports and Virtual Hosts

The port in a virtual host declaration must correspond to a port Apache listens on. Debian-style installations commonly define listening ports in /etc/apache2/ports.conf.

Listen 80

For example, <VirtualHost *:80> requires Apache to listen on port 80. If a virtual host uses another port, such as 8080, ports.conf must include a matching Listen 8080 directive, and network or firewall settings must also permit the traffic.

Practical Inspection

Inspect the Default Configuration

sudo less /etc/apache2/sites-available/000-default.conf

Look for the virtual host address and port, DocumentRoot, and log directives. Compare the document root with the files under /var/www/html.

Inspect Enabled Site Links

ls -l /etc/apache2/sites-enabled/

The output should show links whose targets are files in sites-available. A custom file can exist in the available directory while having no corresponding enabled link.

Troubleshooting

The File Exists but the Site Is Not Served

  • Check whether a link exists in /etc/apache2/sites-enabled.
  • Run sudo apache2ctl configtest.
  • Enable the file with sudo a2ensite example-site.conf if necessary.
  • Reload Apache after the test succeeds.

Apache Will Not Reload

Run the configuration test to identify the error. Common causes include an invalid directive, a malformed or unclosed <VirtualHost> or <Directory> block, and duplicate or conflicting configuration. Correct the reported problem before attempting another reload.

The Wrong Website Appears

  • Verify that ServerName and ServerAlias match the hostname in the request.
  • Confirm that the intended site is enabled.
  • Check whether 000-default.conf is still enabled and handling unmatched requests.
  • Confirm that DNS or local hostname resolution points the domain to the expected server.

Apache Is Not Listening on the Expected Port

Compare the port in the <VirtualHost> declaration with the Listen directives in /etc/apache2/ports.conf. Add or correct the listening port, then run the configuration test and reload Apache.

Permission or File Access Errors

  • Confirm that DocumentRoot points to the intended directory.
  • Review the matching <Directory> block and its Require rules.
  • Check filesystem ownership and permissions so Apache's service account can traverse the directories and read the content.
  • Review the virtual host's error log for the specific path or permission message.

Exam-Relevant Summary

  • /etc/apache2/sites-available stores virtual host configurations but does not activate them automatically.
  • /etc/apache2/sites-enabled contains symbolic links to the configurations Apache should load.
  • a2ensite enables a site; a2dissite disables it without deleting the available file.
  • apache2ctl configtest checks syntax before a reload.
  • systemctl reload apache2 applies valid changes.
  • 000-default.conf commonly provides the default site using /var/www/html.
  • DocumentRoot identifies the site's content directory, while <Directory> controls access to that filesystem path.
  • The virtual host port and ports.conf listening port must agree.

For the related enabled-configuration location, see the Apache sites-available directory guide.