1

私は以前、他の種類の 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 のインクルードを削除しても役に立ちません。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 ドメインでデータが更新されていることに気付くまで、この問題に気付きませんでした。

私は通常、ここで助けを求めることはありません。Web とスタック オーバーフローを同様に調べました。これは、誤ったポート名、VirtualHosts で ServerName を宣言していない、NameVirtualHost を宣言していない *:80、または正しいポートでリッスンしているという問題ではないようです。私は完全に困惑しています。また、この同じ構成は、Linux の RPM ベースのバージョンでも機能します。

4

0 に答える 0