0
votes

I have a bunch of identical apps that are configured to listen on the same url path. For example:

http://server:80/app

I would like to setup an Apache reverse proxy to provide namespacing to the URLs so each app will not have conflicting URLs:

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

I played around with ProxyPass, ReverseProxyPass, and ProxyPreserveHost options to no avail. Specifically when the apps would send a redirect request the redirects would not preserve the namespace.

What would a sample httpd config file look like to apply a namespacing function while acting as a reverse proxy?

This is my sample config (for a single server) that is not working with redirects:

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>

The problem is that http://proxy:80/namespace/app/path sends a redirect which becomes http://proxy:80/app/path/redirect/path (404) which is missing the namespace.

Thanks

1

1 Answers

0
votes

This tutorial provides the answer to my exact use case: http://www.apachetutor.org/admin/reverseproxies

I copied the important snippets below:

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>