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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.