Dynamic virtual host configuration in Apache
Posted
by
Kostas Andrianopoulos
on Server Fault
See other posts from Server Fault
or by Kostas Andrianopoulos
Published on 2012-11-18T02:56:08Z
Indexed on
2012/11/18
5:01 UTC
Read the original article
Hit count: 483
apache2
|virtualhost
I want to make a virtual host in Apache with dynamic configuration for my websites. For example something like this would be perfect.
<VirtualHost *:80>
AssignUserId $domain webspaces
ServerName $subdomain.$domain.$tld
ServerAdmin admin@$domain.$tld
DocumentRoot "/home/webspaces/$domain.$tld/subdomains/$subdomain"
<Directory "/home/webspaces/$domain.$tld/subdomains/$subdomain">
....
</Directory>
php_admin_value open_basedir "/tmp/:/usr/share/pear/:/home/webspaces/$domain.$tld/subdomains/$subdomain"
</VirtualHost>
$subdomain, $domain, $tld would be extracted from the HTTP_HOST variable using regex at request time. No more loads of configuration, no more apache reloading every x minutes, no more stupid logic.
Notice that I use mpm-itk (AssignUserId directive) so each virtual host runs as a different user. I do not intend to change this part.
Since now I have tried:
- mod_vhost_alias but this allows dynamic configuration of only the document root.
- mod_macro but this still requires the arguments of the vhost to be declared explicitly for each vhost.
- I have read about mod_vhs and other modules which store configuration in a SQL or LDAP server which is not acceptable as there is no need for configuration! Those 3 necessary arguments can be generated at runtime.
- I have seen some Perl suggestions like this, but as the author states $s->add_config
would add a directive after every request, thus leading to a memory leak, and $r->add_config
seems not to be a feasible solution.
© Server Fault or respective owner