Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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
01siteA.com -> ../sites-available/siteA.com
02siteB.com -> ../sites-available/siteB.com
99siteZ.com -> ../sites-available/siteZ.com
share|improve this answer

Your Answer

 
discard

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.