Apache2多个基于名称的虚拟主机在一台带有rails / rack的机器上

时间:2013-05-14 15:47:07

标签: ruby-on-rails apache apache2 passenger vhosts

我坚持配置apache以使用基于名称的虚拟主机提供两个不同的站点:

http://experimental/

http://api.experimental/

在一台机器上,这种设置工作正常,apache报告了这一点:

apachectl -D DUMP_VHOSTS
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:*                    is a NameVirtualHost
         default server experimental (/etc/apache2/sites-enabled/00-nowa.conf:3)
         port * namevhost experimental (/etc/apache2/sites-enabled/00-nowa.conf:3)
         port * namevhost api.experimental (/etc/apache2/sites-enabled/00-nowa.conf:15)
Syntax OK

在第二台机器上,这不起作用,两个URL最终都指向第一个应用程序,同一命令的输出还有其他行:

apachectl -D DUMP_VHOSTS
apache2: apr_sockaddr_info_get() failed for experimental
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Tue May 14 15:36:08 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
[Tue May 14 15:36:08 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:*                    experimental (/etc/apache2/sites-enabled/00-nowa.conf:3)
*:*                    api.experimental (/etc/apache2/sites-enabled/00-nowa.conf:15)
Syntax OK

每台计算机的vhost文件都是已损坏的一个:

<VirtualHost *>
  ServerName experimental

  RailsEnv production
  DocumentRoot /home/nowa/nowa_app/nowa/current/public

  <Directory /home/nowa/nowa_app/nowa/current/public >
     Allow from all
     Options -MultiViews
  </Directory>
</VirtualHost>

<VirtualHost *>
  ServerName api.experimental

  RackEnv production

  PassengerMinInstances 2
  PassengerMaxPoolSize 10

  DocumentRoot /home/nowa/nowa_app/services/api_gateway/current/app
</VirtualHost>

正在工作

<VirtualHost *>
    ServerName experimental
    RailsEnv production
    DocumentRoot /home/nowa/nowa_app/nowa/current/public
      <Directory /home/nowa/nowa_app/nowa/current/public >
         Allow from all
         Options -MultiViews
      </Directory>
</VirtualHost>

<VirtualHost *>
    ServerName api.experimental

    RackEnv production

    PassengerMinInstances 2
    PassengerMaxPoolSize 10


    DocumentRoot /home/nowa/nowa_app/services/nowa_api_gateway/current/app
</VirtualHost>

为什么apachectl -D DUMP_VHOSTS的输出不同? 我错过了什么? :C

1 个答案:

答案 0 :(得分:2)

在#httpd irc会议室被问到,并且apache被误解了

<VirtualHost *> 

作为基于IP的vhost条目,而不是基于名称的vhost条目,将其更改为固定它:

<VirtualHost *:80>

这是因为NameVirtualHost在损坏的服务器上定义如下:

NameVirtualHost *:80

完成工作配置:

<VirtualHost *:80>
  ServerName experimental

  RailsEnv production
  DocumentRoot /home/nowa/nowa_app/nowa/current/public

  <Directory /home/nowa/nowa_app/nowa/current/public >
     Allow from all
     Options -MultiViews
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName api.experimental

  RackEnv production

  PassengerMinInstances 2
  PassengerMaxPoolSize 10

  DocumentRoot /home/nowa/nowa_app/services/api_gateway/current/app
</VirtualHost>