Mod_proxy proxy and redirect to specific path

apache-2.2mod-proxy

Today I have two Apache Servers, Server A (192.168.0.5), Server B (192.168.0.10), both running at the same 80 port.

The actual request is from server a and the with my configuration it pass to server b (using mod_proxy), this is working.

Server A configuration:

NameVirtualHost *
<VirtualHost *>
    ServerName owncloud.mydomain.com

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://192.168.0.10:80/
    ProxyPassReverse / http://192.168.0.10:80/
    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

when I access to mycloud.mydomain.com the request is access using SERVER A but with the proxy it "proxies" to server B and then I see the content in server B, that's great but now my content is in mycloud.mydomain.com/owncloud, I don't know how to that url can be proxied and redirected using only mycloud.mydomain.com.

This is other configuration that I use in my server A for use the mod_proxy

 RewriteCond %{HTTP_HOST}   ^mycloud\.mydomain\.com$ [NC]
 RewriteRule   ^/(.*)$ http://mycloud.mydomain.com/$1  [P]

I want when a user access to mycloud.mydomain.com the mod_proxy redirect and proxy to mycloud.mydomain.com/owncloud.

How can I do this?


EDITED BY ME

My new configuration is:

RewriteCond %{HTTP_HOST}   ^owncloud\.mydomain\.com$ [NC]
RewriteRule ^/(.*)$ http://192.168.0.10:80/owncloud/$1 [P,L]
ProxyPassReverse / http://192.168.0.10:80/owncloud/

Im redirecting to owncloud.mydomain.com but the pages doesnt render well (like some css are not loading) but if i just add the /owncloud, everything works, but i dont want the user add the /owncloud. This is not working as expected, do im doing something wrong?

Best Answer

Change thes proxying slightly using these lines:

 RewriteRule ^/(.*)$ http:///192.168.0.10:80/owncloud/$1 [P,L]
 ProxyPassReverse / http://192.168.0.10:80/owncloud/

These lines should replace these lines:

ProxyPass / http://192.168.0.10:80/
ProxyPassReverse / http://192.168.0.10:80/

The above lines say connections coming into / go to http:///192.168.0.10:80/owncloud/ (RewriteRule) and that connections going back out from the proxied server /owncloud/ get rewritten to / (ProxyPassReverse).