【问题标题】:Namespace URL Using Reverse Proxy (Apache)使用反向代理 (Apache) 的命名空间 URL
【发布时间】:2017-11-18 13:02:43
【问题描述】:

我有一堆相同的应用程序被配置为侦听相同的 url 路径。例如:

http://server:80/app

我想设置一个 Apache 反向代理来为 URL 提供命名空间,这样每个应用程序就不会有冲突的 URL:

http://proxy:80/namespace1/app -> http://destserver1:80/app
http://proxy:80/namespace2/app -> http://destserver2:80/app

我尝试了 ProxyPass、ReverseProxyPass 和 ProxyPreserveHost 选项,但无济于事。特别是当应用发送重定向请求时,重定向不会保留命名空间。

在充当反向代理的同时应用命名空间功能的示例 httpd 配置文件是什么样的?

这是我的示例配置(用于单个服务器),不支持重定向:

Listen 80

<VirtualHost *:80>

ServerName 127.0.0.1:80

<Location /namespace/app/>
    ProxyPreserveHost on
    ProxyPass http://destserver:80/app/
    ProxyPassReverse http://destserver:80/app/
</Location>

#ErrorLog logs/test-log
</VirtualHost>

问题是http://proxy:80/namespace/app/path 发送的重定向变为http://proxy:80/app/path/redirect/path (404) 缺少命名空间。

谢谢

【问题讨论】:

    标签: apache reverse-proxy http-redirect


    【解决方案1】:

    本教程提供了我的确切用例的答案:http://www.apachetutor.org/admin/reverseproxies

    我复制了下面重要的sn-ps:

    The fundamental configuration directive to set up a reverse proxy is 
    ProxyPass. We use it to set up proxy rules for each of the application servers:
    
    
    ProxyPass       /app1/  http://internal1.example.com/
    ProxyPass       /app2/  http://internal2.example.com/
    
    ...
    
    The command to enable such rewrites in the HTTP Headers is ProxyPassReverse. 
    The Apache documentation suggests the form:
    
    
    ProxyPassReverse /app1/ http://internal1.example.com/
    ProxyPassReverse /app2/ http://internal2.example.com/
    However, there is a slightly more complex alternative form that I recommend
    as more robust:
    
    
    <Location /app1/>
        ProxyPassReverse /
    </Location>
    <Location /app2/>
        ProxyPassReverse /
    </Location>
    

    【讨论】:

      猜你喜欢
      • 2011-07-13
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      • 2017-07-24
      • 2010-09-20
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多