Many of us host their own website from their home using some old computer or perhaps a Raspberry PI. Using VirtualHosting you could easily host 50+ sites from a single machine, given that said machine has enough space on its hard drive and enough processor power. What now if you want to deviate some of the load to another machine? This is where mod_proxy comes in.
To exemplify, assume we have a set-up as the one in the image below. We have one router/modem combination which is connected to the internet and two LAMP servers which host three websites each. When a request on port 80 (www) comes in, our router automatically forwards this request to LAMP Box 1. If site 1-3 is requested, the LAMP Box 1 server handles the request and returns the website. The question now is how to forward the request to LAMP Box 2, when sites 4-6 would be requested.
The way this is done is fairly easy. You just add a VirtualHost instance to your Apache configuration similar to the one below. In the example code below, when a request comes in for domain.example.com; it is automatically forwarded to the LAMP Box2, which has IP address 192.168.2.201. LAMP Box2 then handles this request and returns the results back to LAMP Box1 which in turn parses the result to the router and so on.
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org ServerName domain.example.com ProxyRequests Off <Proxy *> Require all granted </Proxy> ProxyPass / http://192.168.2.201:80/ ProxyPassReverse / http://192.168.2.201:80/ <Location /> Require all granted </Location> </VirtualHost>