I have a number of largely identical configuration files in my Apache2 configuration, for configuring various subdomains. In most of these configuration files, only the name of the subdomain itself is different from the other files and thus I am trying to figure out if it is possible to set some sort of variable at the top of the config file to easily set things like ServerName
, DocumentRoot
, ErrorLog
, CustomLog
A bit like (which obviously doesn't work):
subdomain=blog
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName ${subdomain}.example.com
DocumentRoot /var/www/${subdomain}.example.com/htdocs
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
ErrorLog /var/log/apache2/${subdomain}.example.com_error.log
CustomLog /var/log/apache2/${subdomain}.example.com_access.log combined
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
An even smarter solution would be if the subdomain
variable can be set through a regex from filename of the configfile.
I did find Dynamically configured mass virtual hosting, but it just doesn't describe exactly what I want.
Running Apache 2.2 on Linux.