Apache Configs shortened -- mod_macro overview
Many people have lengthy configs stating the same blocks over and over again just changed by domain name and home directory.
A bit in the dark this problem has been adressed by Fabien Coelho.
An excerpt of his motivation[1]:
"I hate copy-paste.
When configuring the apache server I often have to copy-paste some parts, especially with virtual hosts to enable similar features or options. In order to avoid this, I would need some kind of macro capabilities in the server runtime configuration files. [...]"
To stay with the philosophy of keeping simple, he just introduced two new "commands"
* <Macro ...> ... </Macro>
* Use ...
So let's get to a real-world example:
<Macro VHostCGI $customer $domain>
<VirtualHost $domain:80>
ServerName $domain
ServerAlias http://www.$domain
DocumentRoot /vaw/www/$customer/docroot/$domain/
ScriptAlias /cgi-bin/ /var/www/$customer/cgi-bin/
ErrorLog /var/log/apache/$customer/logs/$domain-error.log
CustomLog /var/log/apache/$customer/logs/$domain-access.log combined
<Directory /var/www/$customer/cgi-bin/>
Options ExecCGI
</Directory>
</VirtualHost>
</Macro>
Use VHostCGI customer1 example.com
Use VHostCGI customer15 sample.net
Use VHostCGI customer122 iamanexampletoo.org
Another example would be locking some directories if applicable:
<Macro PasswordProtect>
AuthName "Restricted area"
AuthType Basic
AuthUserFile /var/www/.htpasswd
require valid-user
</Macro>
<Directory /var/www/localhost/docroot>
Options Indexes
</Directory>
<Directory /var/www/localhost/docroot/internal>
Use PasswordProtect
Options -Indexes
</Directory>
<Directory /var/www/localhost/docroot/downloads>
Use PasswordProtect
Options +FollowSymLinks
</Directory>
As you can see, you can easily overview what happens and you don't need any copy&paste sections
To get it going on gentoo, just do
emerge mod_macro
and enable it in etc/conf.d/apache with -D MACRO
More information about the module can be found at its homepage[2]
[1] http://www.coelho.net/mod_macro/#motivation
[2] http://www.coelho.net/mod_macro/