電子書籍の厳選無料作品が豊富!

質問させて頂きます。
apache2.2.21にてweb鯖を立てて、ドメインを取得しDDNSにてテストしています。
test.comというドメインにバーチャルホストにて web1.test.comとweb2.test.comを設定
した場合に、
なぜかtest.comとweb1.test.comが同じ内容が表示されてしまいます。
web2は通常通り表示されます。

詳しい方が居ましたら間違い点を教えて下さい。

httpd-vhostsの内容
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "C:/web/web1"
ServerName web1.babayasu.info
ErrorLog "logs/web1.localhost-error.log"
CustomLog "logs/web1.localhost-access.log" common
<Directory "C:/web/web1">
order deny,allow
allow from ALL
Options Indexes FollowSymLinks ExecCGI IncludesNoExec
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:/web/web2"
ServerName web2.babayasu.info
ErrorLog "logs/web1.localhost-error.log"
CustomLog "logs/web1.localhost-access.log" common
<Directory "C:/web/web2">
order deny,allow
allow from ALL
</Directory>
</VirtualHost>

A 回答 (1件)

あまりきちんと設定を見ていませんが、動作としてはそうなるものです。


VirtualHost設定は、どの条件にも当てはまらなかった場合のdefaultを、「最初に宣言されたVirtualHost」にするという仕様になっています。

http://httpd.apache.org/docs/2.2/vhosts/examples …
> www.example.com は 最初にあるため、優先順位は一番高くなり、
> default もしくは primary のサーバと考えることができます。
> つまり、リクエストが どの ServerName ディレクティブにも
> マッチしない場合、 一番最初の VirtualHost により扱われます。

もし、ホスト名を入れない場合にそのサーバコンテンツへ接続できないようにしたい、ということであれば、それらよりも前に一つ、ダミーのVirtualHost設定を入れておく必要があります。

この回答への補足

ご回答ありがとうございます。

早速ダミー用にwwwというバーチャルホストをhttpd-vhostsの一番上作成しDNSとapacheの設定を変更してみました。
ですが、ホスト名を入力せずに接続してみるとやはり、blog.が表示されてしまいます。

”それらよりも前に一つ、ダミーのVirtualHost設定を入れておく必要があります。”
はhttpd-vhostsの設定のことで間違いないでしょうか?

解凍お願いします。

補足日時:2011/12/30 22:44
    • good
    • 0
この回答へのお礼

ありがとうございました。
キャッシュを消去して再度表示してみるとうまくいきました
ありがとうございました

お礼日時:2011/12/30 23:05

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!