How to host multiple sites from several servers behind a single IP address



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.

Situation sketch

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.

System setup


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; it is automatically forwarded to the LAMP Box2, which has IP address 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>

    ProxyRequests Off
    <Proxy *>
        Require all granted

    ProxyPass /
    ProxyPassReverse /

    <Location />
        Require all granted


Further reading

If you have questions or comments, feel free to drop a line! Like what you read? Share this page with your friends and colleagues.


What is the answer to Two + Eight?
Please answer with a whole number, i.e. 2, 3, 5, 8,...