Joomla!-开源天空

2009-01-10
您所在的位置: 首页 > Linux系统 > 基础知识 > [收藏]利用Macro简化apache的配置

[收藏]利用Macro简化apache的配置

Joomla! 开源天空  作者:管理员  2008-11-19 22:57
  • 摘要:如何利用apache Macro简化重复的apache虚机配置。

许多人有冗长的配置文件,只为了改改域名和主目录,就要一遍遍地声明同样的块。这个有点不太清楚的问题已经被Fabien Coelho提出来了。

“我恨复制-粘贴。当配置appache服务器时,我经常要复制-粘贴一些部分,特别是配置虚拟主机,要打开类似的特性或参数时。为了避免这个问题,我需要服务器的运行配置文件有某种宏能力。[……]”

    为坚持"保持简单"的哲学,他只引入了两个新“命令”:

 

  • <Macro ...> ... </Macro>
  • Use ...

 

    让我们看一个真实世界中的例子吧:

<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打开这个选项就行了。

  发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码