【问题标题】:How to put different host entries on same linux server, for different virtual hosts? [closed]对于不同的虚拟主机,如何在同一 Linux 服务器上放置不同的主机条目? [关闭]
【发布时间】:2012-03-10 13:31:51
【问题描述】:

设置是: 使用 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

【问题讨论】:

标签: php linux apache vhosts


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    我会这样做:

    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-01-22
      • 2014-01-09
      • 1970-01-01
      • 2021-08-20
      • 2013-10-06
      • 2020-01-17
      • 2019-03-10
      • 2015-06-05
      • 2013-03-28
      相关资源
      最近更新 更多