Apache und mod_macro (Englisch, da für GWN)

Hier stellen wir Anleitungen zu bestimmten Themen zur Verfügung. Diese sind sicherlich teilweise speziell auf eine Distribution bezogen, sollten aber von allen Linux-Neulingen gelesen werden, da sich viele Fragen dadurch schon vorher erledigen...

Apache und mod_macro (Englisch, da für GWN)

Beitragvon jokey » Do Okt 11, 2007 21:08

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

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

<Directory /var/www/localhost/docroot>
Options Indexes
<Directory /var/www/localhost/docroot/internal>
Use PasswordProtect
Options -Indexes
<Directory /var/www/localhost/docroot/downloads>
Use PasswordProtect
Options +FollowSymLinks

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/
From Zero to Gentoo in 30 seconds
LUG Flensburg
LUG Flensburg
Beiträge: 10
Registriert: Sa Jan 29, 2005 14:52
Wohnort: Uetersen

Zurück zu Anleitungen

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast