Hugo Apache Macros
Apache macros allow for fast and consistent site setup. Here I show how to setup mod_macro and provide a example configurationUsing Apache
I like to use templates for things I will do more then once. Apache has a template system named mod_macro
enable apache macro module
a2enmod macro
LoadModule macro_module /usr/lib/apache2/modules/mod_macro.so
Create macro templates
Example Development SSL Virtual Host
Here I enable
1. apache generated directory index access for local networks
2. SSL Certificates known at a certain path managed by certbot
3. Specific cache rules for object types and filenames
<Macro SSLHostDev $host $port $dir $chain $key>
<VirtualHost *:$port>
ServerName $host
DocumentRoot "$dir"
SSLEngine on
SSLCertificateFile $chain
SSLCertificateKeyFile $key
<Directory "$dir">
Require ip 192.168.8.0/24
Require ip 192.168.193.0/24
Options Indexes FollowSymLinks
</Directory>
ErrorLog ${APACHE_LOG_DIR}/$host_error.log
CustomLog ${APACHE_LOG_DIR}/$host_access.log combined
<IfModule mod_expires.c>
<FilesMatch "\.(html)$">
ExpiresActive On
ExpiresDefault "access plus 10 minutes"
</FilesMatch>
<FilesMatch "\.(xml)$">
ExpiresActive On
ExpiresDefault "access plus 90 minutes"
</FilesMatch>
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|webp)$">
Header set Cache-Control "s-max-age=3600, public"
ExpiresActive On
ExpiresDefault "access plus 30 days"
</FilesMatch>
ExpiresByType image/wepb A2592000
ExpiresByType image/jpeg A2592000
</IfModule>
</VirtualHost>
</Macro>
define macro configuration line
Once a macro is defined you can enable sites with a single line. The line says use the template named SSLHostDev each space separated entry is related to the variables defined at the start of the template.
<Macro SSLHostDev $host $port $dir $chain $key>
Use SSLHostDev 65483-d.rasor.org 443 /www/65483-d.rasor.org/public /etc/letsencrypt/live/rasor.org/fullchain.pem /etc/letsencrypt/live/rasor.org/privkey.pem
If you would like email or rss feed updates. Visit the Subscribe page