MySQL-based vhosting¶
Module: mod_mysql_vhost
- Table of contents
- MySQL-based vhosting
Description¶
DEPRECATED: mod_mysql_vhost has been replaced with mod_vhostdb and mod_mysql_vhost will be removed from a future version of lighttpd
Note: since lighttpd 1.4.46, subsumed by mod_vhostdb
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 gstrauss over 4 years ago · 22 revisions