Docs ModMySQLVhost » History » Revision 18
« Previous |
Revision 18/22
(diff)
| Next »
stbuehler, 2009-02-17 10:59
Module mod_mysql_vhost - MySQL-based vhosting¶
- Table of contents
- Module mod_mysql_vhost - MySQL-based vhosting
Description¶
With MySQL-based vhosting you can store the path to a given host's document root in a MySQL database.
Note: Keep in mind that only one vhost module should be active at a time. Don't mix mod_simple_vhost with mod_mysql_vhost.
Options¶
Example:
mysql-vhost.db = "lighttpd" mysql-vhost.user = "lighttpd" mysql-vhost.pass = "secret" mysql-vhost.sock = "/var/run/mysqld/mysqld.sock" mysql-vhost.sql = "SELECT docroot FROM domains WHERE domain='?';" mysql-vhost.hostname = "localhost" mysql-vhost.port = 3306
If specified, mysql-vhost.hostname
overrides mysql-vhost.sock
.
MySQL setup:
GRANT SELECT ON lighttpd.* TO lighttpd@localhost IDENTIFIED BY 'secret'; CREATE DATABASE lighttpd; USE lighttpd; CREATE TABLE domains ( domain varchar(64) not null primary key, docroot varchar(128) not null ); INSERT INTO domains VALUES ('host.dom.ain','/http/host.dom.ain/');
Wildcard subdomains with same docroot¶
Insert domain names like '%.example.com' into the sql table, and use the following query:
mysql-vhost.sql = "SELECT docroot FROM domains WHERE '?' like domain;"
Per-vhost configuration (not using the module)¶
You can obviously create a lighttpd config from a database (load it via the include_shell
command in the lighttpd config);
but there is no point in using the same table again with mod_mysql_vhost - just use server.document-root.
Your script should output something like that for every vhost:
$HTTP["host"] == "<DOMAIN_FROM_DATABASE>" { server.document-root = "<DOCROOT_FROM_DATABASE>" <CONFIG_FROM_DATABASE> }
Please note that you should not allow your users to modify the config which gets inserted here, or they just may use include_shell with "rm -rf /" - which gets probably executed with root.
And you have to restart your webserver every time you change something.
Updated by stbuehler almost 16 years ago · 18 revisions