Apache Proxy and Rewrite, append directory to URL

Posted by ionFish on Server Fault See other posts from Server Fault or by ionFish
Published on 2012-09-22T19:12:50Z Indexed on 2012/09/22 21:39 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

I have a backend server running on http://10.0.2.20/ from the local network, which serves similar to this:

/ (root)
|
|_user1/
| |_www/
| |_private/
|
|_user2/
  |_www/
  |_private/
(etc.)

Accessing http://10.0.2.20/user1/ of course, contains 'www' and 'private' folders and is proxied through a public server using Apache's Reverse Proxy. I'd like it so the following happens:

http://public-proxy-server/user1/ actually shows the content from http://10.0.2.20/user1/www/ without indicating it in the URL. (/private/ would not be accessible via the public proxy server).

The key here, is for it to be dynamic, so all requests to http://public-proxy-server/*/should show content from http://10.0.2.20/*/www/. Again, the proxy currently works fine; below is the config:

(On the public server)

<VirtualHost *:80>
        ServerName www.domain.com
        ProxyRequests Off
        ProxyPreserveHost On
        ProxyVia full
        ProxyPass / http://10.0.2.20/
        ProxyPassReverse / http://10.0.2.20/
</VirtualHost>

(On the backend server)

<VirtualHost *:80>
        ...
        #this directory contains folders 'user1' and 'user2'
        DocumentRoot /var/www/
        ...
</VirtualHost>

© Server Fault or respective owner

Related posts about apache2

Related posts about proxy