1

让我在这里再解释一下——我正在使用BOX1,我想访问BOX2,但是我想使用一个域来访问它(example.com),所以我的域指向box1,现在我如何获取示例。 com 从 box2 获取内容而不实际重定向到 box2 的 IP 地址?

4

3 回答 3

0

我们对“反向代理”的定义似乎有所不同。我倾向于将其等同于负载平衡和缓存,而您只是想要基于 GeoIP 查找发出 301/302 重定向的东西。

<?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();
于 2012-12-05T22:49:32.033 回答
0

你可以用 PHP 编写一个非常简单的反向代理。您基本上只需获取请求参数并使用 curl 或 file_get_contents 传递它们。例如:

<?php
  $external_url = 'http://www.anotherserver.com' . $_SERVER['REQUEST_URI'] . $_REQUEST['QUERY_STRING'];
  print file_get_contents($external_url);
?>

查看这篇文章了解更多详情。

于 2014-04-18T16:15:52.610 回答
0

感谢这篇文章,我想通了:http: //techzinger.blogspot.ca/2007/07/writing-reverse-proxy-in-php5.html

于 2012-12-05T23:12:06.547 回答