msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

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
  </Directory>
</VirtualHost>
</Macro>

Use VHost customer_A example.com
Use VHost customer_B example.net
Use VHost customer_C example.org

Another example

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

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

More info can be found on the mod_macro website.

Tags: ,

Comments are closed.