0

设置是:两个应用程序使用 apache 配置中的 vhost 条目托管在同一 linux 服务器上。说 :

http://greatapp.example.com

http://superapp.example.com

他们都有一个功能,他们可以向第三个 url 进行服务器端 http 请求(使用 php cURL / file_get_contents):

http://apis.example.com

现在主机文件'/etc/hosts'中有一个主机条目

xx.xx.xx.xx       apis.example.com

这仅适用于 greatapp.example.com 代码,不适用于 superapp.example.com。

如何配置服务器,让greatapps.example.com使用主机条目,但superapp.example.com使用apis.example.com的公共 ip

4

2 回答 2

1

它不能直接完成:主机名空间是每个主机全局的。

您可以在具有不同/etc/hosts文件的虚拟机中运行其中一个 apache。

于 2012-02-20T06:55:21.093 回答
0

这是我的做法:

  1. 我的每个应用程序都有一个可以读取的配置文件。该配置文件可以指定要使用的 url。您可以使用现有库来读取配置文件。在本例中,我将使用 Zend_Config_Ini。这是您的配置文件对于出色应用程序的外观:

[设置]

urls.third_party = 'xxx.xxx.xxx.xxx'

这是一个用于超级应用的

[设置]

urls.third_party = 'http://apis.example.com'

2.使用 Zend_Config_Ini 从配置文件中读取 url,例如:

require_once 'Zend/Config/Ini.php';
$config = new Zend_Config_Ini('application.ini', 'settings');
$app_config = $config->toArray();

$third_party_url = $app_config['urls']['third_party'];

我认为这种方式更灵活,因为您可以轻松更改相关应用程序配置文件中的 url。

于 2012-02-20T07:16:34.123 回答