Web-server – Two servers, two domains, one ip. mod_proxy beginner

apache-2.2mod-proxyweb-server

I run two virtual web servers (both running apache2 on debian). I have just one external IP, but two domains, and I want a domain going to each of the servers.

I've understood that I need a Reverse Proxy, and I enabled both the mod_proxy and the mod_proxy_http modules on the "primary server". Do I need to enable anything on the "secondary server"?

I also understood that I need to write some things in a virtual host file, but what? On the primary server, I have a virtual host file for one of the domains, and some for subdomains. I want domain1.tld to go to the primary server (port 80 is forwarded to it, so that works) and domain2.tld to go to the other server (internal ip 192.168.0.x). No ports needs to be forwarded to it, right? So, what to add and in which virtual host file? Or a new one? Other questions suggest adding ProxyPass and ProxyPassReverse, but I'm lost anyway, and I just don't understand the apache documentation.

Thanks in advance

Best Answer

You might want to look at using HAProxy, which does this sort of thing very well.

In a nutshell, you'd create a third VM which runs HAProxy and has your IP address. Your HAProxy configuration will determine to which Apache instance the request is sent on the back end.

Take a look at the site and if you want to give it a try, then you can ask more questions.

Related Topic