许多人有冗长的配置文件,只为了改改域名和主目录,就要一遍遍地声明同样的块。这个有点不太清楚的问题已经被Fabien Coelho提出来了。
为坚持"保持简单"的哲学,他只引入了两个新“命令”:
让我们看一个真实世界中的例子吧:
<Macro VHostCGI $customer $domain>
<VirtualHost $domain:80>
ServerName $domain
ServerAlias 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
</Directory>
</VirtualHost>
</Macro>
Use VHostCGI customer1 example.com
Use VHostCGI customer15 sample.net
Use VHostCGI customer122 iamanexampletoo.org如果适用的话,另一个例子将锁定一些目录:
<Macro PasswordProtect> AuthName "Restricted area" AuthType Basic AuthUserFile /var/www/.htpasswd require valid-user </Macro> <Directory /var/www/localhost/docroot> Options Indexes </Directory> <Directory /var/www/localhost/docroot/internal> Use PasswordProtect Options -Indexes </Directory> <Directory /var/www/localhost/docroot/downloads> Use PasswordProtect Options +FollowSymLinks </Directory>
你看看,你可以简单地回顾发生了什么,你用不着复制和粘贴任何小节。:)
如果您正好使用的是Gentoo,您只要emerge mod_macro,并且在/etc/conf.d/apache里用-D MACRO打开这个选项就行了。