A chronological documentation test project, nothing serious, really!

09 Nov 2007 Shortening Apache Configs using mod_macro

Posted by

It is possible to use macros in the Apache config files to shorten them and make them easier to read and manage. To use this you have to install mod_macro if it’s not already installed in your distribution.

Sample mod_macro usage

<Macro VHost $customer $domain>
<VirtualHost $domain:80>
  ServerName $domain
  ServerAlias www.$domain
  DocumentRoot /vaw/www/$customer/htdocs/$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,noIndexes

Use VHost customer_A
Use VHost customer_B
Use VHost customer_C

Another example

<Macro PasswordProtect>
AuthName "Restricted area"
AuthType Basic
AuthUserFile /var/www/.htpasswd
require valid-user

<Directory /var/www/domain/htdocs>
Options Indexes
<Directory /var/www/domain/htdocs/internal>
Use PasswordProtect
Options -Indexes
<Directory /var/www/domain/htdocs/downloads>
Use PasswordProtect
Options +FollowSymLinks

More info can be found on the mod_macro website.

Tags: ,

Comments are closed.