Name-based Virtual Hosts Serving Default DocumentRoot
I spent a while trying to figure out why one of my virtual hosts was serving the default DocumentRoot instead of the one in the virtual host section. I finally figured out the reason and am sharing it in case anyone else runs into the same issue.
I’m running Ubuntu and the default VirtualHost configuration file didn’t have a ServerName. I use Name-Based Virtual Hosts and the domain name that matched the default entry had a reverse DNS entry to the IP. My theory is that Apache does a reverse DNS lookup if the ServerName is missing, because the domain in question mapped to the server IP. The fix was to add a ServerName of localhost in the default entry.
In short, if your name-based virtual hosts aren’t matching the ServerName correctly, make sure the default entry (the first file in the sites-enabled directory) has a ServerName.