Apache virtual hosts and reverse proxy

apache-2.2reverse-proxyvirtualhost

I have many virtual hosts whose domain names map to a single Apache server (let's call it server1). Under certain circumstances, all URLs for a certain virtual host should be served by a different server instead (let's call it server2).

What's the easiest way to accomplish that? Can I simply set server2 to use the same name-based virtual host setup as server1, and then rely on server1's X-Forwarded-Host headers (i.e. will server2 do the right thing based on just those header's)? By "same name-based virtual host setup" I mean the "real" domain names (i.e. the domain names which map to server1's IP).

Best Answer

you can indeed use the mod_proxy module. It runs fine with vhosts. Basically, the main server will receive all the requests, and when a certain url/domain is called, mod_proxy will redirect this domain to another server (server 2) it looks like this on server 1

<VirtualHost *>
ServerName server1.com
Hosted on the server
</VirtualHost *>

<VirtualHost *>
ServerName server2.com
// mod_proxy directives in order to redirect this domain name to the other server //
</VirtualHost>

And there is a good tutorial : http://www.apachetutor.org/admin/reverseproxies