Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
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.

share|improve this answer
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 -> ../sites-available/ -> ../sites-available/ -> ../sites-available/
share|improve this answer
Am I correct in that if I rename those symlinks, then I can't use eg. a2dissite but have to manually remove the symlink? At least that was the experience on my server... – TheStoryCoder Feb 25 at 7:42
I think you can use the helper but you need to specify the exact link name: a2dissite – Jorge Bernal Feb 26 at 9:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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