需要通过Apache代理传递环境变量

时间:2020-02-12 01:25:42

标签: apache environment-variables reverse-proxy virtualhost http-proxy

后端:我将Tomcat连接到Apache,并将JKMount'ed连接到webapps.demo.example.com

前端:为主虚拟主机设置了demo.example.com。我有一个应用程序必须代理到BACKEND。除了ServerName和ContextPath需要从FRONTEND中拉出之外,此功能非常有用。

请按照以下说明进行以下尝试: https://www.xinotes.net/notes/note/1954/

<VirtualHost *:80>
    DocumentRoot "/home/example.com"
    ServerName demo.example.com

    ProxyPassInterpolateEnv On
    RewriteEngine on
    RewriteMap lowercase int:tolower

    RewriteRule ^ - [E=SERVER_NAME:${lowercase:%{SERVER_NAME}}]

    ProxyPreserveHost On

    ProxyPass "/Project1/Test" "http://webapps.demo.example.com/Test1"
    ProxyPassReverse /Project1/Test http://%{SERVER_NAME} interpolate

    ErrorLog "/home/logs/httpd/example-error_log"
    CustomLog "/home/logs/httpd/example-access_log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/home/webapps"
    ServerName webapps.demo.example.com

    JkMount /Test1 worker1
    JkMount /Test1/* worker1

    ErrorLog "/home/logs/httpd/webapps-error_log"
    CustomLog "/home/logs/httpd/webapps-access_log" common
</VirtualHost>

添加ProxyPreserveHost On后,我的代理链接返回404而不是Test1应用程序。

从FRONTEND服务器传递某些环境变量的同时,代理的正确方法是什么?如果绝对必要,我可以更改Test1应用程序。但是我确实需要一个变量来使用。 Project1不能是硬编码值。

mod_proxy_html或mod_headers可以在这里提供帮助吗?

0 个答案:

没有答案
相关问题