Dup Ver Goto 📝

VirtualHosts

To
25 lines, 159 words, 1232 chars Page 'VirtualHosts' does not exist.

This page at digitalocean

This stackoverflow question](https://stackoverflow.com/questions/31504003/apache-virtual-hosts-not-working-as-expected) contains something important that isn't obvious and would take a lot of doc-diving to find. The [TL;DR is that apache2 uses the ServerName directive to distinguish virtual hosts, not the FQDN at the top.

If you have some virtual hosts whose config looks like:

<VirtualHost *:80>
...
  ServerName myserver1

but you have at least one config that looks like:

<VirtualHost server2:80>
...
  ServerName server2

then the non-wildcard config takes precedence over all the wildcard hosts. So for every virtual host, apache2 stops with the first <VirtualHost server2:80> that matches the incoming server address. So e.g. if in your hosts you have

127.0.0.1 myserver1 server2

then the <VirtualHost server2:80> will match for anything local. Thus you must make sure that the top line of every config is of the form

<VirtualHost *:80>

as even a single config that is not *:80 will screw things up.