Multiple Apache servers on one IP, using port 80

apache-2.2port-forwarding

I wanted to gather peoples thoughts on the following situation:

Two Apache servers, A1 and A2.

Both servers are behind a router that can forward port 80 to only one ip, so how do you manage two servers hosting different domains on one IP?

I've looked into mod_proxy with little success, and wondered if there was any "DNS port forwarding" feature you can install to manage packets.

For example IP address is 87.166.55.44 (fake don't try it :p).

A1 hosts foo.com
A2 hosts bar.com

port 80 forwarded to A1.
A1 realises it's a request for bar.com, so acts as a proxy between A2 and the router.

I hope this makes sense, and any help would be appreciated!

Best Answer

technically it's not possibly unless your router has a built in reverse proxy or some layer 7 routing which none that I know of do. If you want to really do it this way and want to make it scalable, then you will need to have a reverse proxy which has maps of site names and where to proxy it to.

<VirtualHost *:80>
  ServerName www.domain-a1.com
  ProxyRequests Off
  ProxyPass http://servera1/
  ProxyPassReverse http://servera1/
</VirtualHost>

<VirtualHost *:80>
  ServerName www.domain-a2.com
  ProxyRequests Off
  ProxyPass http://servera2/
  ProxyPassReverse http://servera2/
</VirtualHost>

This will not work for SSL sites as the SSL negotiations happen before knowing which site it's for, but then switch SSL certs to pass to them (chicken and the egg), etc.

Related Topic