I am wanting to mimic a load balancer where if a person goes to
http://example.com/mysite
they will either be seeing the content of:
http://server2.example.com/mysite
or
http://server3.example.com/mysite
Using PHP I can randomly determine which site the user goes to, but how do I get that to display at http://example.com/mysite
? Do I somehow use an iframe
that takes up the entire height and width of the window? Or is there a way that would work better?
Basically, I want the user to only ever see http://example.com/mysite
in the address bar and be oblivious as to which server they are viewing the page on. I don't mind if they look at the source code to see it, but I want to make sure the URL is the same.
The two sites make use of JavaScript (both server-side and client-side), PHP, and HTML. The sites make use of long-polling as well on the server-side JavaScript (Node).
Update
Thanks to Lawrence Cherone's suggestion I have implemented a load balancer in Apache as follows:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName jpl.example.com
ProxyRequests off
<Proxy "balancer://mycluster">
BalancerMember "http://203.0.113.22:3000"
BalancerMember "http://203.0.113.23:3000"
</Proxy>
ProxyPass "/test/" "balancer://mycluster/"
ProxyPassReverse "/test/" "balancer://mycluster/"
</VirtualHost>
Two remaining issues:
Issue 1
In order to allow for subdirectories I had to add a trailing slash to the ProxyPass
and ProxyPassReverse
lines.
This works to go from:
jpl.example.com/test/
=> http://203.0.113.22:3000
jpl.example.com/test/subdir1/
=> http://203.0.113.22:3000/subdir1/
jpl.example.com/test/subdir2/
=> http://203.0.113.22:3000/subdir2/
But won't work if I leave off the trailing slash:
jpl.example.com/test
jpl.example.com/test/subdir1
jpl.example.com/test/subdir2
Any ideas how to get it to work if the user neglects to type in the trailing slash?
Issue 2
The second issue was becoming too convoluted so I moved it to its own question. The issue involves long polling no longer working because it cannot find socket.io.