Apache2 reverse-proxy multiple locations

Apache2mod-proxyreverse-proxy

I am trying to configure a proxy for my local application (bittorent sync) using apache2 mod_proxy_html. I run multiple instances of the local app, each for a different user. To access the web interface remotely, I need to redirect the address

sub.example.com/user1 to the local app listening on 127.0.0.1:8888 and

sub.example.com/user2 to 127.0.0.1:8889 etc.

The local app has some hard-coded links to /gui that need to be redirected too.

In my latest attempt, I managed to get the proxy running for a single user like this:

<VirtualHost *:80>
ServerName sub.example.com
ProxyRequests Off

ProxyPass /user1 http://127.0.0.1:8888
ProxyPassReverse /user1 http://127.0.0.1:8888
ProxyHTMLURLMap http://127.0.0.1:8888 /user1
Redirect permanent /gui /user1/gui

</VirtualHost>

Now, I would like to extend the solution for multiple users and ports, i.e. something like this:

<VirtualHost *:80>
ServerName sub.example.com
ProxyRequests Off

<Location /user1>
    ProxyPass http://127.0.0.1:8888
    ProxyPassReverse http://127.0.0.1:8888
    ProxyHTMLURLMap http://127.0.0.1:8888 /user1
    Redirect permanent /gui /user1/gui
</Location>

<Location /user2>
    ProxyPass http://127.0.0.1:8889
    ProxyPassReverse http://127.0.0.1:8889
    ProxyHTMLURLMap http://127.0.0.1:8889 /user2
    Redirect permanent /gui /user2/gui
</Location>

</VirtualHost>

which unfortunately does not work as I intended.

Best Answer

Why not defining an virtualhost by user, like user1.sub.example.com, user2.sub.example.com

You cannot define twice the same Redirect permanent in the same context (here only one virtual host)