【问题标题】:How To include external httpd.conf in Apache configuration based on Environment Variable如何根据环境变量在 Apache 配置中包含外部 httpd.conf
【发布时间】:2011-09-06 14:01:00
【问题描述】:

我想根据外部设置的环境变量在我的主 Apache httpd.conf 中包含一个或另一个外部 httpd.conf 文件。

所以我想做类似的事情:

if $(DEV_ENV) == "main"
Include "first file"
if $(DEV_ENV) == "alt"
Include "second file"

我一直在查看 mod_setenv 模块,但它用于在 Apache 配置中设置环境变量。 如何使用环境变量并对其值进行比较?

【问题讨论】:

    标签: apache httpd.conf


    【解决方案1】:

    抱歉,您不能在 Includes 上执行这种动态逻辑。当然,Debian 版本允许通过替换模式直接引用环境变量,例如

    Include conf/${APACHE_RUNTIME_TYPE}/*.conf
    

    浏览“Apache2 envvars”以了解更多信息。

    【讨论】:

      【解决方案2】:

      看看ifdefine。这将评估在命令行上传递的选项,而不是环境变量。以下符合您的要求:

      <IfDefine main>
      Include "first file"
      </IfDefine>
      <IfDefine alt>
      Include "second file"
      </IfDefine>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-15
        • 2015-02-11
        相关资源
        最近更新 更多