2017-06-15 25 views
0

我有一堆相同的應用程序被配置爲偵聽相同的url路徑。例如:命名空間URL使用反向代理(Apache)

http://server:80/app

我想建立一個Apache反向代理,以提供命名空間的網址,以便每個應用程序將不會有衝突的網址:

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)其缺少命名空間的重定向。

感謝

回答

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>