Linode suggests defining each virtual host in a separate file in /etc/apache2/sites-available (on ubuntu) and then enabling each site using a2ensite. I am coming from a VPS where all my virtual hosts are defined in one httpd.conf file, and trying to convert things into the recommended format.

One of the things I have set up is a wildcard subdomain for my main site, which are later mapped to userspace. However, I also have static subdomains. I am under the impression that the static subdomains need to live above the wildcard in my configuration so if one of the static subdomains is accessed, apache uses the correct virtual host instead of hitting the wildcard.

If this is true, how can precedence be defined if using one file per site? Or do I need to just stick to one site file and stick all the subdomains in the same file as the main virtual host?


Other than being a bit more manageable and easier to enable/disable vhosts, there's no reason that you need to maintain that structure (/etc/apache2/sites-available/conf_file) If you prefer to keep everything in the same file, then just continue doing that.

  • Fair enough, but is there a way to do * subdomains reliably in that structure? – Daniel Vandersluis Feb 11 '10 at 23:31

Apache processes the contents of config sub-directories in alpha-numeric sort order (properly called a local-collation sequence, but Apache doesn't' use that terminology).

Therefore, use filenames to set the order. You can prefix or suffix all the filenames, or just some of them, invent names that sort properly or whatever else floats your boat so long as they sort correctly. However, I personally prefer using prefixes because it's absolutely clear what you are doing.

  • 2
    This is the correct answer, and is what is used by those who use this method. Much better than the "Well don't move your arm if it hurts" accepted answer. I prefix my sites_enabled symlinks with a three-digit number to set the precedence. – cincodenada Nov 21 '12 at 22:10

With that file structure, you keep the files on /etc/apache2/sites-available and a2ensite just link those files on /etc/apache2/sites-enabled.

If you want to set precedence, you need to make sure that the files in sites-enabled are sorted according to your preference. Example:

$ ls -l /etc/apache2/sites-enabled/
00default -> ../sites-available/default
01siteA.com -> ../sites-available/siteA.com
02siteB.com -> ../sites-available/siteB.com
99siteZ.com -> ../sites-available/siteZ.com
  • Am I correct in that if I rename those symlinks, then I can't use eg. a2dissite siteB.com but have to manually remove the symlink? At least that was the experience on my server... – TheStoryCoder Feb 25 '16 at 7:42
  • I think you can use the helper but you need to specify the exact link name: a2dissite 02siteB.com. – Jorge Bernal Feb 26 '16 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.