Two servers hosting different websites on the same IPandport

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Two servers hosting different websites on the same IPandport

Postby Spunkybd » 20. April 2013 08:19

I have seen this documentation http://httpd.apache.org/docs/2.2/vhosts/examples.html

But that does not go over what i would like to do.

I have 2 Servers with 2 different websites that need to be on port 80.

How would i set that up from the inside?
Spunkybd
 
Posts: 2
Joined: 20. April 2013 08:15
XAMPP Version: 5.6.3
Operating System: Server 08/W7

Re: Two servers hosting different websites on the same IPand

Postby Nobbie » 20. April 2013 16:34

With one IP and one Port only (i.e. Port 80), you can only run one Server public.

Take one of these Servers as standard public server. To access the other (hidden) Server, you must either use a different domain name name or a directory name beyond the first Server (and domain). If you use different (public) domain names (what i recommend and i only show example for this case), you have to define two virtualhosts in the public server, one for the public server itself and one for the hidden server. You can show the websites of the hidden server using a "reverse proxy" in the matching virtualhost declaration.

Simple example:

Server1 is domain1.com and domain2.com, but
Server2 "should" serve for domain2.com

Server1 has Public IP and must also have a local IP in the LAN (you can assign either more than one IP to one network card or use two network cards in Server1, one for the WAN and one for the LAN). Server2 is part of the LAN does only have a local IP in the LAN.

If you use a router instead (where both Server1 and Server2 are connected to the router), the Public IP is assigned to the router, Server1 and Server2 have local LAN IPs and the router must be configured to "forward" all requests from Port 80 to Server1.

In httpd.conf of Server1 you have to define 2 vitualhost domain1.com, domain2.com. For domain1.com apply DocumentRoot and so on, for domain2.com you create an reverse proxy which yields to the local LAN IP of Server2:

(Basic example where xxx.xxx.xxx.xxx is the Public IP of Server1 or the local LAN IP of Server1 if it is connected to a router, lan.lan.lan.lan is the Local LAN IP of Server2)

Code: Select all
NameVirtualHost xxx.xxx.xxx.xxx :80
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName domain1.com
DocumentRoot /var/www/htdocs
....
</VirtualHost>
<VirtualHost xxx.xxx.xxx.xxx:80>
ServerName domain2.com
ProxyPass / http://lan.lan.lan.lan
ProxyPassReverse / http://lan.lan.lan.lan
</VirtualHost>


On Server2 you simply configure an Apache Server listening on lan.lan.lan.lan with ServerName lan.lan.lan.lan

Of course you may apply an internal ServerName for Server2 (like local.server2 or similar) and apply this to the hosts file of Server1 and Server2 with Local IP lan.lan.lan.lan and then use this ServerName in all instances instead of the local IP lan.lan.lan.lan. This is not quite necessary, but some people dont like naked IPs. Neither the local IP nor the ServerName of Server2 is "visible" to the Internet, for any user in the WWW it will look like as Server1 serves domain2.com as well as domain1.com (what actually is the case, but Server1 shows the contents of Server2 for domain2.com).

For mor information read the Apache documentation about Reverse Proxys (the above example is the most basic reverse proxy as possible).
Nobbie
 
Posts: 6781
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: gsmith and 50 guests