首页 文章

命名空间URL使用反向代理(Apache)

提问于
浏览
0

我有一堆相同的应用程序配置为侦听相同的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) ,缺少命名空间 .

谢谢

1 回答

  • 0

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

    我复制了以下重要的片段:

    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>
    

相关问题