Apache Macros – Simplify your config
Many people host small time hobby websites or even websites for family members, friends and clients on a single server. This will lead to quite a lot of repetition for the same apache site definitions over and over again. Thankfully Apache Macros mod will solve many of these issues. This mod will let you create config templates, that can then be re-used over multiple sections of code, allowing you to pass in variables to fill in on use.
Lets get it installed!
sudo apt-get install libapache2-mod-macro
sudo a2enmod macro
Now, you can start using Macros in your site definitions, to replace common configurations.
ยป Official Documentation for Apache Macros
Examples of Apache Macros
In this you can see a pretty simple Domain macro. This will set the ServerName, and sets a www. alias. Now we look at the Site macro. In this example you will see it calling other macros for Log, GrantAccess and ForceDomain.
To use this, one could simply add inside of the <VirtualHost> this line:
Use Site mysite.com
And then accessing mysite.com would redirect to www.mysite.com, and log to /var/log/apache2/sites/mysite.com_access.log. Needless to say that likely cuts out 99% of the configuration you’re doing for a simple wordpress site you host for a relative.
And since the Apache Macros are parsed at config load, there’s no impact to your servers performance for using it!
For enterprise grade setups, you’re likely already using Puppet to get the same benefits and only running 1 product per server any-ways, but for those of us kicking it hobby level, Apache macros helps quits a bit! Enjoy ๐