How to setup reverse proxy to forward domain names to different servers?

I have a CentOS5 server with Apache, which have one external IP address with the hostname "example.com".

What I like is that

sub1.example.com sends http requests to 10.10.10.10
sub2.example.com sends http requests to 10.20.20.20

Looking at the mod_proxy for Apache, I can't figure out what I need to configure to get that.

Does someone know how to do this?


Solution 1:

You'll have to create two virtual hosts for apache one for each subdomain, acting as a reverse proxy to the specified ip.

something along the lines of

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName sub1.example.com

    ErrorLog "var/log/sub1_error_log"
    CustomLog "var/log/sub1_access_log" common

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://10.10.10.10/
    ProxyPassReverse / http://10.10.10.10/
</VirtualHost>

<VirtualHost *:80>
    ServerName sub2.example.com

    ErrorLog "var/log/sub2_error_log"
    CustomLog "var/log/sub2_access_log" common

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass / http://10.20.20.20/
    ProxyPassReverse / http://10.20.20.20/
</VirtualHost>