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.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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 way ls would list a directory). This is hinted at by the included default site on Ubuntu being called 000-default. So based on that, to create a new default VirtualHost, you need to create a new VirtualHost config in sites-available called (for instance) 00_default_vhost.conf and then enable it with a2ensite.

share|improve this answer
Completely didn't occur to me about the number ordering. I basically renamed default to 00-default and restarted Apache, now it goes exactly to the default where I specified. Thank you much. –  Shannon May 14 '11 at 21:23

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.