Using Apache 2.x as a Proxy to Other Physical Servers
If you have multiple sites (domains or sub-domains), that you want to host on a separate physical web server(s), you can proxy requests from an apache server to other servers. This uses a similar Virtual Host configuration as when you are pointing many sites (domains or sub-domains) to different directories on a single server.
Assuming Apache 2 is installed and working on Ubuntu or a Debian style Linux distro:
1. Add the proxy module
sudo a2enmod proxy
2. Create a new file in:
/etc/apache2/sites-available
3. Name this file the same name is your domain or sub-domain (for easy management later) e.g. beta.mydomain.com
The file should then contain:
NameVirtualHost *
<virtualhost *> Servername beta.mydomain.com DirectoryIndex index.html index.php ProxyRequests On ProxyPreserveHost On ProxyVia full <proxy> Order deny,allow Allow from all </proxy> Proxypass / http://192.168.1.161/ Proxypassreverse / http://192.168.1.161/
</virtualhost>
...where:
- Servername is the domain name (sub-domain or otherwise)
- the uri in ‘Proxypass’ and ‘Proxypassreverse’ is that of the separate physical server and apache installation within (in this case) or outside of your local area network.
- the url can include a port if you want to proxy to a mongrel cluster hosting your rails app
4. Let Apache know about this new ‘virtual’ host:
a2ensite beta.mydomain.com
5. Restart the Apache service:
/etc/init.d/apache2 restart
You should be all set to build out your distributed web server network.