Let me explain it more here -- I am using BOX1, I want to visit BOX2, but I want to use a domain to visit it(example.com), so my domain is pointing to box1, now how do I get example.com to fetch content from box2 without actually redirecting to IP address of box2?
Our definition of 'reverse proxy' seems to differ. I tend to towards equating it with load balancing and caching, while you simply want something to issue 301/302 redirects based on a GeoIP lookup.
<?php
$servers = array(
'CA' => array('1.1.1.1', '2.2.2.2'),
'US' => array('3.3.3.3', '4.4.4.4')
);
$cc = geoip_country_code_by_name( $_SERVER['REMOTE_ADDR'] );
if( in_array($cc, $servers) ) {
$server = $servers[$cc][rand(0,count($servers[$cc]))];
} else {
$server = '5.5.5.5';
}
header('Location: ' . $server);
exit();
I figured it out thanks to this post: http://techzinger.blogspot.ca/2007/07/writing-reverse-proxy-in-php5.html
You can write a very simple reverse proxy in PHP. You basically just take the request parameters and pass them on using curl or file_get_contents. For example:
<?php
$external_url = 'http://www.anotherserver.com' . $_SERVER['REQUEST_URI'] . $_REQUEST['QUERY_STRING'];
print file_get_contents($external_url);
?>
Check out this article for more details.