1. Overview

In this tutorial, we look at the reason why sites-available, sites-enabled, and conf.d directories exist on some Linux systems.

When running a Linux-based web server, its configuration files exist in a structure of directories. For a Debian, it’s under /etc/apache for the Apache webserver or /etc/nginx for the NGINX webserver. These configuration directories consist of some subfolders, and we’ll take a closer look at some of them.

In particular, we’ll explain the function and usage of sites-enabled, sites-available, and conf.d, as well as the difference between them.

2. The conf.d Directory

The conf.d directory (hence the .d appendix) is just a general container for extensive config files (hence the conf prefix).

However, this is only a convention, not even specific to web servers. In fact, many applications can be configured this way. For example, let’s look at an example Dovecot mail server configuration:

$ ls -las /etc/dovecot
total 48
4 drwxr-x--- 5 vmail dovecot 4096 Jul 19 14:10 .
4 drwxr-xr-x 99 root root 4096 Aug 20 16:35 ..
4 drwxr-x--- 2 vmail dovecot 4096 Jul 19 13:09 conf.d
4 drwxr-x--- 2 vmail dovecot 4096 Jul 19 13:09 conf.keyhelp.d
[...]

As we can see, there is a conf.d directory with the following contents:

$ ls -las /etc/dovecot/conf.d
total 144
 4 drwxr-x--- 2 vmail dovecot  4096 Jul 19 13:09 .
 4 drwxr-x--- 5 vmail dovecot  4096 Jul 19 14:10 ..
 8 -rw-r----- 1 vmail dovecot  5248 Dec 22  2020 10-auth.conf
 4 -rw-r----- 1 vmail dovecot  1781 Dec 22  2020 10-director.conf
 4 -rw-r----- 1 vmail dovecot  4073 Dec 22  2020 10-logging.conf
20 -rw-r----- 1 vmail dovecot 18068 Jul 20  2021 10-mail.conf
 4 -rw-r----- 1 vmail dovecot  3569 Dec 22  2020 10-master.conf
 4 -rw-r----- 1 vmail dovecot  3315 Jul 20  2021 10-ssl.conf
 4 -rw-r----- 1 vmail dovecot   291 Jul 20  2021 10-tcpwrapper.conf
 4 -rw-r----- 1 vmail dovecot  1657 Dec 22  2020 15-lda.conf
 4 -rw-r----- 1 vmail dovecot  3111 Dec 22  2020 15-mailboxes.conf
 8 -rw-r----- 1 vmail dovecot  4520 Dec 22  2020 20-imap.conf
 4 -rw-r----- 1 vmail dovecot  1367 Dec 22  2020 20-lmtp.conf
 [...]

In conf.d, there are many files with configuration options, starting with two numbers and then a descriptive name. When the server is run, they are applied in ascending order, whereby if an option exists twice, the later entry overwrites the earlier. In general, this helps make custom configuration updates safe.

While conf.d is relatively universal across Linux distributions, other config directories are not.

3. Apache, sites-available, and sites-enabled on Debian

The directories, sites-available, and sites-enabled are specific features of Debian Linux.

In sites-available, we can store virtual host settings for a web server like Apache. Each represents a separate site, available but not enabled. To do that, we can use Debian’s a2ensite and a2dissite commands.

Once enabled, a symlink (symbolic link) for that configuration in sites-available is created in sites-enabled.

When we run the a2ensite command, it offers us a list of virtual hosts from sites-available:

$ a2ensite
Your choices are: 000-default default-ssl
Which site(s) do you want to enable (wildcards ok)?

Here, we have the two default sites from a fresh Debian installation: 000-default and default-ssl. Choosing the asterisk (*) means we want to enable all virtual hosts.

After any change of this configuration, it’s best to run apache2ctl -t to check if the configuration validity:

$ apache2ctl -t
Syntax OK

If there are no errors, we restart to apply the changes:

# apache2ctl graceful

Alternatively, we can use systemctl restart apache2.service. Importantly, both commands need elevated privileges, so we issue them as root or via sudo. Let’s see how this works for another popular web server.

4. NGINX on Debian

The above way to deal with enabling and disabling a virtual host is not part of the NGINX web server, but there is a port of the features from the Debian Apache configuration to NGINX. It introduces the nginx_ensite and nginx_dissite commands, similar to the ones Apache provides.

As stated above, this is not the official NGINX way of handling things. This web server relies on the usage of conf.d:

http {
[...]
   include /etc/nginx/conf.d/*.conf;
}

Here, the NGINX config dictates that virtual hosts are .conf files under the path /etc/nginx/conf.d, e.g., /etc/nginx/conf.d/example.com.conf.

To disable a virtual host, we don’t use nginx_dissite example.com. Instead, we just rename the file to example.com.disabled so that the globbing for *.conf won’t match anymore.

5. Conclusion

In this article, we discussed why there might be configuration directories called conf.d, sites-available, and sites-enabled and how to take advantage of their existence. In particular, we noted that the latter two are Debian-specific, while the former is relatively universal.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.