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.
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.
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’.
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.
Thank you! That did the trick.