简体   繁体   English

如何使用mod_rewrite中的环境变量在httpd.conf中插值proxypass

[英]How to use environment variable from mod_rewrite for interpolate proxypass in httpd.conf

I'm using apache 2.4 and trying to use environment variable inside conf file for proxy pass. 我正在使用apache 2.4并尝试在conf文件中使用环境变量进行代理传递。 There's a thread [ Apache proxypass using a variable URL with interpolate ]talking about this: 有一个线程[ Apache proxypass使用带有插值的可变URL ]讨论这个问题:

RewriteEngine on
RewriteMap lowercase int:tolower

#This sets the variable to env:
RewriteRule ^ - [E=SERVER_NAME:${lowercase:%{SERVER_NAME}}]

#Now interpolate makes variables available for proxypass & proxypassreverse:
ProxyPassInterpolateEnv On
ProxyPass / ajp://${SERVER_NAME}:8009/ interpolate
ProxyPassReverse / ajp://${SERVER_NAME}:8009/ interpolate

But when I tried this myself, I get a "AH00111: Config variable ${SERVER_NAME} is not defined" error. 但是当我自己尝试此操作时,出现“ AH00111:配置变量$ {SERVER_NAME}未定义”错误。 Which means Apache2.4 treats the ${SERVER_NAME} as config variable, rather than environment variable. 这意味着Apache2.4将$ {SERVER_NAME}视为配置变量,而不是环境变量。

I also tried using the mod_rewrite sytax for the variable, like this, 我也尝试将mod_rewrite语法用于变量,像这样,

ProxyPass / ajp://%{ENV:SERVER_NAME}:8009/ interpolate
ProxyPassReverse / ajp://%{ENV:SERVER_NAME}:8009/ interpolate

But %{ENV:SERVER_NAME} was treated as plaintext string, and created an error since it's not a valid URL pass. 但是%{ENV:SERVER_NAME}被视为纯文本字符串,并且由于不是有效的URL传递而创建了一个错误。

Config variables are defined with "Define" block at server launch. 在服务器启动时,使用“ Define”块定义配置变量。 What I want is to have the SERVER_NAME changing at runtime using mod_rewrite. 我想要的是在运行时使用mod_rewrite更改SERVER_NAME。 I can't use the mod_rewrite [P] argument, since I need to have the ProxyPassReverse block working with variable as well. 我不能使用mod_rewrite [P]参数,因为我还需要使ProxyPassReverse块与变量一起工作。 mod_rewrite can't deal with rewriting the response, and therefore can't mimic the function of ProxyPassReverse. mod_rewrite无法处理重写响应,因此无法模仿ProxyPassReverse的功能。

Any ideas on how to use environment variable in interpolate proxypass conf directives? 关于如何在插值proxypass conf指令中使用环境变量的任何想法?

It turns out Apache will still load and work fine, even with the warnings, using this syntax: 事实证明,使用以下语法,即使有警告,Apache仍可以加载并正常工作:

ProxyPassReverse / ajp://${SERVER_NAME}:8009/ interpolate

This issue was identified in this mailing list thread . 此邮件列表线程中发现了此问题。 The discussion is about another issue, but they mention this problem and discuss the idea of adding a second interpolation syntax to ProxyPass, etc. However, I have not found a bug report, and it seems as of Apache 2.4.10, the mod_proxy code still supports only the ${varname} syntax, which conflicts with the overall httpd.conf interpolation. 讨论是关于另一个问题的,但是他们提到了这个问题,并讨论了向ProxyPass等添加第二种插值语法的想法。但是,我还没有发现错误报告,并且从Apache 2.4.10开始, mod_proxy代码仍然仅支持${varname}语法,该语法与整体httpd.conf插值冲突。

I haven't found a way to disable those specific warnings, but if you are willing to live with the warnings, Apache should still work for you. 我还没有找到一种方法来禁用那些特定的警告,但是如果您愿意接受这些警告,那么Apache应该仍然可以为您工作。

One caveat is that if there is a system environment variable present with the same name when Apache is loading, it will overwrite the value you are trying to interpolate at runtime. 一个警告是,如果在加载Apache时存在一个具有相同名称的系统环境变量,它将覆盖您尝试在运行时插入的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM