Iptables – Forwarding HTTP requests to VMs behind a virtual network

iptablesnetworkingreverse-proxyvirtualization

I'm trying to set up a virtual machine host (currently running ubuntu + KVM) which will host a number of VMs for different applications. For example, we have a wiki running on one VM and a web application running on another.

     Host
     /  \ 
    VM1 VM2

Internally, the VMs live on their own virtual network with their own IPs, however externally, there is only one IP address which is the IP address of the host.

There is a domain set up on our network that points to the Host's IP and I can set up an iprule to forward traffic destined for the host directly to one of the VMs. However, in order to make both VMs accessible to the outside world, somehow I need to forward requests based on the URL.

Ideally I'd like to forward requests by subdomain e.g.

http://vm1.host/ -> host -> VM1
http://vm2.host/ -> host -> VM2

but alternatively by the URL path:

http://host/vm1 -> host -> VM1
http://host/vm2 -> host -> VM2

I have already installed Apache on the Host machine. What kind of forwarding/redirecting/aliasing/reverse-proxying rules would I need to get this kind of network setup to work? Is there anything extra needed to handle subdomains?

Best Answer

Are you serving any webpages from the Host itself? If not, and all of the web data is on VM1 and VM2, then probably Apache on the Host is not the best solution. Most likely you should use something like haproxy or squid on the host to forward the requests to Apache running on VM1&2

Related Topic