如何在不同的虚拟主机上将不同的主机条目放在同一个Linux服务器上?

时间:2012-02-20 06:51:26

标签: php linux apache vhosts

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

http://greatapp.example.com

http://superapp.example.com

他们都有一个功能,他们将服务器端的http请求发送到第三个URL(使用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的公共广告

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

我将如何做到这一点:

  1. 我的每个应用都会有一个将被阅读的配置文件。该配置文件可以指定要使用的URL。您可以使用现有库来读取配置文件。在这个例子中,我将使用Zend_Config_Ini。以下是适用于优秀应用的配置文件:
  2.   

    [设置]

         

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

    这是superapp的一个

      

    [设置]

         

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

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

    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'];
    

    我认为您可以通过这种方式更加灵活,因为您可以轻松地轻松更改相关应用的配置文件中的网址。

相关问题