3

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?

3 Answers 3

1

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.

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

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.

1
  • 3
    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. Nov 21, 2012 at 22:10
3

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
2
  • 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... Feb 25, 2016 at 7:42
  • I think you can use the helper but you need to specify the exact link name: a2dissite 02siteB.com. Feb 26, 2016 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .