简体   繁体   中英

Apache2 multiple name-based virtual hosts on one machine with rails/rack

Am stuck on configuring apache to serve up two different sites with Name based virtual hosts at:

http://experimental/

and

http://api.experimental/

On one machine this setup works fine, and apache reports this:

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

On the 2nd machine this does not work, both URLS end up pointing to the first app, it's output of the same command is which has additional : lines:

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

The vhost files for each machine are this for the broken one:

<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>

And working :

<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>

Why is the output of apachectl -D DUMP_VHOSTS different? What have I missed? :C

Asked on the #httpd irc room and turns out apache was misinterpreting

<VirtualHost *> 

as an IP based vhost entry, not a name based one, changing it to this fixed it:

<VirtualHost *:80>

This was because NameVirtualHost was defined like this on the broken server:

NameVirtualHost *:80

Complete working config:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM