Reputation: 61
I'm trying to migrate my virtualhosts to a mysql database using vhost_dbd_module.
In the various examples I find online, they instruct me to use "ServerName *" as a wildcard in the VirtualHost.
When I configure my VirtualHost this way, the server just defaults back to the default DocumentRoot. It does not query the mysql database.
<VirtualHost *:80>
# catch all other requests that don't get caught above
ServerName *
# fallbackDocumentRoot in case mysql server is down
DocumentRoot /var/html/404
DBDriver mysql
DBDParams "host=<hostname> user=<user> dbname=<dbname>"
DBDocRoot "SELECT documentRoot FROM virtualhosts WHERE serverName = %s" HOSTNAME
</VirtualHost>
However, when I change it to this (specify the ServerName to domain.tld), it works properly (queries the database for domain.tld and returns the proper documentroot for domain.tld)
<VirtualHost *:80>
# catch all other requests that don't get caught above
ServerName domain.tld
# fallbackDocumentRoot in case mysql server is down
DocumentRoot /var/html/404
DBDriver mysql
DBDParams "host=<hostname> user=<user> dbname=<dbname>"
DBDocRoot "SELECT documentRoot FROM virtualhosts WHERE serverName = %s" HOSTNAME
</VirtualHost>
Any ideas what is misconfigured?
Upvotes: 0
Views: 3949
Reputation: 61
After messing around some more, it appears that ServerName * only works when it is the FIRST VirtualHost in the system.
I moved it first in order, with a few other virtualhosts beneath it (with more specific ServerName example.tld) and both the DB hosts and the statically configured hosts worked.
Upvotes: 0