Apache HTTPD别名/目录根据环境变量有条件配置

发布于 2025-01-27 12:39:46 字数 775 浏览 4 评论 0原文

我们配置了一个Apache HTTPD服务器,以允许浏览特定的文件目录。我们想基于指定部署系统的环境变量设置该目录位置(DEV,QA,POD)。这是我尝试这样做的尝试:

<If "osenv('APP_ENV') == 'dev'">
  LogMessage "The value of APP_ENV is dev"
  Define DATA_MOUNT /data/AA_images
</If>
<Else>
  LogMessage "The value of APP_ENV is other"
  Define DATA_MOUNT /data/DIM_Factory
</Else>


Alias /data ${DATA_MOUNT}
<Directory ${DATA_MOUNT}>
  Options Indexes FollowSymlinks MultiViews
  IndexOptions FancyIndexing VersionSort FoldersFirst NameWidth=32
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
</Directory>

从日志中,我可以看到“ App_env的值为DEV的值”是正确触发的,但是 second 定义是设置的,而不是第一个。启动服务器时,我将获取DIM_FACTORY目录。这是为什么?似乎定义命令没有作为IF/else块的一部分进行评估。

我应该这样做吗?

We have an Apache httpd server configured to allow browsing of a specific file directory. We'd like to set that directory location based on an environment variable that specifies where the system is deployed (dev, qa, prod). Here is my attempt to do that:

<If "osenv('APP_ENV') == 'dev'">
  LogMessage "The value of APP_ENV is dev"
  Define DATA_MOUNT /data/AA_images
</If>
<Else>
  LogMessage "The value of APP_ENV is other"
  Define DATA_MOUNT /data/DIM_Factory
</Else>


Alias /data ${DATA_MOUNT}
<Directory ${DATA_MOUNT}>
  Options Indexes FollowSymlinks MultiViews
  IndexOptions FancyIndexing VersionSort FoldersFirst NameWidth=32
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
</Directory>

I can see from the logs that "The value of APP_ENV is dev" is correctly triggered, but the second Define is being set, not the first. When I start the server, I'm getting the DIM_Factory directory. Why is that? Seems like the Define commands are not being evaluated as part of the If/Else block.

Is there a different way I should be doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文