Apache2 Ubuntu 12.10仅识别默认虚拟主机

时间:2013-03-05 02:29:22

标签: apache2 virtualhost ubuntu-10.10

我之前遇到过这个问题,其他版本的Linux通常都是愚蠢的,但我认为我已经排除了所有这些可能性。我在apache2 Ubuntu 12.10上使用多个虚拟主机。根据Ubuntu默认设置:

[ports.conf]

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    # If you add NameVirtualHost *:443 here, you will also have to change
    # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
    # to <VirtualHost *:443>
    # Server Name Indication for SSL named virtual hosts is currently not
    # supported by MSIE on Windows XP.
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

Apache2.conf is ubuntu default and loads ports.conf.

I have two virtualhosts
<VirtualHost *:80>

 ServerName *.staging.mydomain.com

 Options -Indexes FollowSymLinks

 UseCanonicalName Off
 DocumentRoot /var/www/staging/app/application/current/app

 ErrorLog "/var/log/error.log"
 CustomLog "/var/log/custom_error.log" common

 <ifModule env_module>
  SetEnv PHP_ENV staging
 </ifModule>
 <Directory />
  AllowOverride none
 </Directory>

 <Directory "/var/www/staging/app/application/current/app">
  RewriteEngine On

  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

 </Directory>

</VirtualHost>
<VirtualHost *:80>

 ServerName *.devtest.mydomain.com

 Options -Indexes FollowSymLinks

 UseCanonicalName Off
 DocumentRoot /var/www/devtest/app/application/current/app

 ErrorLog "/var/log/error.log"
 CustomLog "/var/log/custom_error.log" common

 <ifModule env_module>
  SetEnv PHP_ENV develop
 </ifModule>
 <Directory />
  AllowOverride none
 </Directory>

 <Directory "/var/www/devtest/app/application/current/app">
  RewriteEngine On

  RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

 </Directory>

</VirtualHost>

对somevalue.devtest.mydomain.com的请求将解析为与somevalue.staging.mydomain.com相同的文档根目录。如果我按顺序翻转VirtualHosts的声明,那么它的反向运行;对somevalue.staging.mydomain.com的请求将解析为与somevalue.devtest.mydomain.com相同的文档根目录。无论我尝试过什么,我都无法让两个主机同时工作。我在WAMP本地工作并且遇到了同样的问题,但它只是一个错位的NameVirtualHost *:80使它工作。将listen和NameVirtualHost移出ports.conf进入apache2.conf并删除Include for ports.conf没有帮助。 Apache不会产生任何错误。日志级别设置为debug。

因为我知道你会问,是的,我已经使用a2enmod启用了这些网站。是的,我重新启动了apache。我已经完全重启服务器了。如果我启用了ubuntu $sudo a2enmod default附带的默认虚拟主机,那么它将捕获somevalue.devtest.mydomain.com和somevalue.staging.mydomain.com的所有请求。

虚拟主机已启用并解析$sudo apache2ctl -S

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server *.staging.mydomain.com (/etc/apache2/sites-enabled/wild.mydomain.com:19)
         port 80 namevhost *.staging.mydomain.com (/etc/apache2/sites-enabled/wild.mydomain.com:19)
         port 80 namevhost *.devtest.mydomain.com (/etc/apache2/sites-enabled/wild.mydomain.com:51)**strong text**

最后,请求在服务器curl -Lv http://test.staging.mydomain.com上解析

* About to connect() to test.staging.mydomain.com port 80 (#0)
*   Trying 1.1.1.1...
* connected
* Connected to test.staging.mydomain.com (1.1.1.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.27.0
> Host: test.staging.mydomain.com
> Accept: */*
>
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
< Date: Tue, 05 Mar 2013 02:22:28 GMT
< Server: Apache/2.2.22 (Ubuntu)
< X-Powered-By: PHP/5.4.6-1ubuntu1.1
< Vary: Accept-Encoding
< Content-Length: 18
< Content-Type: text/html
<
* Connection #0 to host test.staging.mydomainy.com left intact
<pre>staging</pre>* Closing connection #0

我删除了IP和域,但它肯定能正确解析。服务器上的一切运行正常,事实上我甚至没有注意到这个问题,直到我在登台环境中并发现数据在devtest域上更新而不是暂存。

我通常不会在这里寻求任何帮助,而且我已经搜索过网络和Stack Overflow。这似乎不是错误的端口名称的问题,不是在VirtualHosts中声明ServerName,或者没有声明NameVirtualHost *:80或正确的端口上侦听。我完全难过了。此外,这个相同的配置适用于基于RPM的Linux版本。

0 个答案:

没有答案