Set Default Virtual Host

5 posts / 0 new
Last post
#1 Mon, 08/18/2008 - 02:55
notacake

Set Default Virtual Host

How can I set a named virtual host to be the default? At the moment when I go to the IP address it comes up with a seemingly random virtual host (always the same one, but it wasn't the first or the last that was created - which would have made some kind of sense).

I've tried changing the *:80 virtual host in the Apache module, yet it doesn't seem to have any effect. I can't figure out where it's deciding which is the default.

Mon, 08/18/2008 - 04:45
andreychek

In theory, it should be the first one it comes to.

In RHEL/CentOS, where all the VirtualHosts go in the httpd.conf file, the first VirtualHost section should become the "default".

In Ubuntu, there's a file named /etc/apache2/enabled-sites/000-default.conf -- whatever the contents it are becomes the default Virtual Host.

It shouldn't be random though unless somehow the order of the VirtualHost directives is changing.
-Eric

Mon, 08/18/2008 - 05:40 (Reply to #2)
notacake

The 000-default.conf is set up to use the document root I want, yet it still uses a different virtual host.

The virtual host it's using seems to be the first alphabetically based on subdomains, i.e. 'dev.a.com' is being shown as the default, even though there's an 'a.com'.

Mon, 08/18/2008 - 08:10 (Reply to #3)
Joe
Joe's picture

It selects in a "first best match" manner. If the 000-default.conf virtual host is a *:80 address, and all of your virtual hosts are 192.168.1.1:80 style, then when you hit 192.168.1.1, one of those will win the selection process.

We do not recommend you use * for any virtual host for this reason (and others). It makes it difficult to predict and understand what Apache is doing and why.

--

Check out the forum guidelines!

Mon, 08/18/2008 - 09:09 (Reply to #4)
notacake

Thank you! That did the trick.

Topic locked