我之前在使用其他版本的 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 并删除 ports.conf 的 Include 并没有帮助。Apache 不会产生错误。日志级别设置为调试。
因为我知道你会问,是的,我已经使用 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 版本。