I have set up a Ubuntu Linux VPS with Moonshine (a Ruby on Rails deployment plugin/script) and hosting multiple sites on it (despite Moonshine being intended for one site/application), so far working well.
One little issue that I have with my server is that whenever I accidentally set up a vhost wrong or a vhost is not found, the browser is directed to the very first vhost site that I set up. Which concerns me because I don't want one site accidentally being associate with the other in case of some error or issue; what I would "rather" have it do is direct to some default place (like /var/www/default/oops.html) if there are any issues.
I've Googled the subject and the common answer is that order is everything in the vhost files, except I think that is assuming I have ALL my vhosts in one file. Instead, my vhosts are set up separately in the sites-available/enabled folders of apache (mydomain1.com, mydomain2.com, etc) and 'a2ensite' respectively, so how would I go about "ordering" these? (One of these files is a 'default' file, but doesn't seem to do anything.)
One other thing I saw was specify a default host in httpd.conf, except when I attempted to do so, it completely redirected ALL my vhost sites to the default.
On Ubuntu your vhosts will be loaded via
Include
statements within the/etc/apache2/apache2.conf
configuration file. You're right that Apache treats the first VirtualHost it finds as the default if it can't match a request but just because the VirtualHost directives aren't in the same file doesn't stop you from ordering them.Down the bottom of
/etc/apache2/apache2.conf
you can find the line:# Include the virtual host configurations:
Include sites-enabled/
This is where Apache is picking up your VirtualHosts specified in /etc/apache2/sites-enabled/ so you've got two options:
Put an include to add a new VirtualHost above the above Include line in the
apache2.cnf
config file.Or order the files in
sites-enabled
. I'm not sure on the exact mechanism Apache uses to read these files but I'm assuming it's alphabetical with numbers first (in the same wayls
would list a directory). This is hinted at by the included default site on Ubuntu being called000-default
. So based on that, to create a new default VirtualHost, you need to create a new VirtualHost config insites-available
called (for instance)00_default_vhost.conf
and then enable it witha2ensite
.