【Apache】複数ドメイン運用の設定方法は?


http://localhost/
へのアクセスは期待通りですが、
http://test.local/
へアクセスすると、http://localhost/ へのアクセスと同じになってしまいます。

どこをどう修正すれば
http://test.local/ へのアクセスで
C:\temp\test\index.html が開かれるようになるのでしょうか?

【hosts】
--------
127.0.0.1 localhost
127.0.0.1 test.local
--------

【httpd.conf】
--------
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/xampp/htdocs
<Directory "C:\xampp\htdocs">
Options All
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName test.local
DocumentRoot C:/temp/test
<Directory "C:\temp\test">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
--------

回答の条件
  • 1人5回まで
  • 登録:
  • 終了:2008/05/08 14:13:49
※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。

回答4件)

id:b-wind No.1

回答回数3344ベストアンサー獲得回数440

バーチャルホストの設定をするには - NameVirtualHost

NameVirtualHost の指定はしていますか?

id:thwd

httpd.confに

NameVirtualHost 127.0.0.1

Listen 80

と書いたらApache起動しなくなりました。

httpd -S

=> syntax OK

2008/05/07 15:59:25
id:samasuya No.2

回答回数315ベストアンサー獲得回数11

ServerAlias test.local

を追加でどうでしょうか?

id:thwd

<VirtualHost *:80>

ServerName test.local

DocumentRoot D:/temp/test

ServerAlias test.local

<Directory "D:\temp\test">

Options All

DirectoryIndex index.php

AllowOverride All

Order allow,deny

Allow from all

</Directory>

</VirtualHost>

としてみましたが、ダメでした。

変わりません。

2008/05/07 15:50:05
id:samasuya No.3

回答回数315ベストアンサー獲得回数11

ポイント45pt

コメント欄解放していただければ、ありがたいです・・・。

2度目の回答すみません。


NameVirtualHost *

とした上で、

<VirtualHost *>

  (略)

  xxx.xxx.net

</VirtualHost>

でどうでしょうか?

id:thwd

【httpd.conf】

--------

NameVirtualHost *

Listen 80

<VirtualHost *:80>

ServerName localhost

...

</VirtualHost>

<VirtualHost *:80>

ServerName test.local

DocumentRoot D:/temp/test

ServerAlias test.local

<Directory "D:\temp\test">

...

</Directory>

</VirtualHost>


としましたが、Apache起動しません。

Syntax は OKと出ます。

NameVirtualHost *

Listen 80

をコメントアウトするとApache起動します。

が、http://test.local/ へのアクセスが http://localhost/

と同じになってしまいます。

xampp 1.6.6a (Apache 2.2 ?) です。

2008/05/07 23:59:27
id:wdc No.4

回答回数11ベストアンサー獲得回数0

ポイント45pt

hostsファイル(Windowsの)

127.0.0.1 localhost

127.0.0.1 test.localhost


根本的に

httpd.conf の DocumentRoot より上には行けないですよ。

従いまして以下のようにしてみてください。


httpd-vhosts.conf に書いてインクルード または httpd.conf に直接。

NameVirtualHost *:80


<VirtualHost *:80>

DocumentRoot "C:/xampp/htdocs"

ServerName localhost

</VirtualHost>


<VirtualHost *:80>

DocumentRoot "C:/xampp/htdocs/test"

ServerName test.localhost

</VirtualHost>


http://test.local/ は間違いですね。

http://test.localhost/ ではないでしょうか。


上記設定でうまくいかない場合、他の原因が考えられると思います。

今はそこまではわかりませんが…

id:thwd

そうでしたか。

意外と不便ですね(^^;

皆さんありがとうございました!

2008/05/08 14:09:55
  • id:samasuya
    エラーログになにかメッセージでてませんか?


    あと、:80は、取ってみてください。
    <VirtualHost *:80>

    <VirtualHost *>


    うちは、Apache/2.0.54なんで、ちがうのかもしれませんが・・・。
  • id:thwd
    NameVirtualHost *
    Listen 80
    を書いておくとApacheが起動してくれません。

    コマンドラインで httpd.exeを実行した結果
    (<VirtualHost *>としてあります)


    C:\xampp\apache\bin>httpd.exe
    [Thu May 08 13:10:02 2008] [error] VirtualHost *:80 -- mixing * ports and non-*
    ports with a NameVirtualHost address is not supported, proceeding with undefined
    results
    [Thu May 08 13:10:02 2008] [error] VirtualHost _default_:443 -- mixing * ports a
    nd non-* ports with a NameVirtualHost address is not supported, proceeding with
    undefined results
    (OS 10048)通常、各ソケット アドレスに対してプロトコル、ネットワーク アドレス、ま
    たはポートのどれか 1 つのみを使用できます。 : make_sock: could not bind to addr
    ess 0.0.0.0:80
    no listening sockets available, shutting down
    Unable to open logs

    C:\xampp\apache\bin>httpd.exe -S
    [Thu May 08 13:10:37 2008] [error] VirtualHost *:80 -- mixing * ports and non-*
    ports with a NameVirtualHost address is not supported, proceeding with undefined
    results
    [Thu May 08 13:10:37 2008] [error] VirtualHost _default_:443 -- mixing * ports a
    nd non-* ports with a NameVirtualHost address is not supported, proceeding with
    undefined results
    VirtualHost configuration:
    wildcard NameVirtualHosts and _default_ servers:
    *:* is a NameVirtualHost
    default server localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:74)

    port 443 namevhost localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf
    :74)
    port * namevhost localhost (C:/xampp/apache/conf/httpd.conf:529)
    port * namevhost test.local (C:/xampp/apache/conf/httpd.conf:542)

    Syntax OK

  • id:thwd
    【httpd.conf】
    --------
    # NameVirtualHost *
    # Listen 80

    <VirtualHost *>
    ServerName localhost
    DocumentRoot C:/xampp/htdocs
    ...
    </VirtualHost>

    <VirtualHost *>
    ServerName test.local
    DocumentRoot D:/temp/test
    ServerAlias test.local
    ...
    </VirtualHost>


    結果は同じでした。
    http://test.local/

    http://localhost/
    C:\xampp\htdocs
    へのアクセスとなってしまいます。

  • id:thwd
    【error.log】
    ---------
    [Thu May 08 13:37:33 2008] [notice] Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5 mod_perl/2.0.3 Perl/v5.8.8 configured -- resuming normal operations
    [Thu May 08 13:37:33 2008] [notice] Server built: Jan 18 2008 00:37:19
    [Thu May 08 13:37:33 2008] [notice] Parent: Created child process 368
    [Thu May 08 13:37:38 2008] [notice] Child 368: Child process is running
    [Thu May 08 13:37:38 2008] [notice] Child 368: Acquired the start mutex.
    [Thu May 08 13:37:38 2008] [notice] Child 368: Starting 250 worker threads.
    [Thu May 08 13:37:38 2008] [notice] Child 368: Starting thread to listen on port 443.
    [Thu May 08 13:37:38 2008] [notice] Child 368: Starting thread to listen on port 80.
    [Thu May 08 13:38:28 2008] [notice] Parent: Received shutdown signal -- Shutting down the server.
    [Thu May 08 13:38:28 2008] [notice] Child 368: Exit event signaled. Child process is ending.
    [Thu May 08 13:38:29 2008] [notice] Child 368: Released the start mutex
    [Thu May 08 13:38:30 2008] [notice] Child 368: All worker threads have exited.
    [Thu May 08 13:38:35 2008] [notice] Child 368: Child process is exiting
    [Thu May 08 13:38:36 2008] [notice] Parent: Child process exited successfully.
    --------

    実は設定内容に間違いはなく、別の原因でうまくいっていない、
    ということなのでしょうか(TT)
  • id:b-wind
    >根本的に、
    >httpd.conf の DocumentRoot より上には行けないですよ。
    それは違うでしょ。
    VirtualHost 毎に任意のディレクトリを DocumentRoot に指定できる。
    もちろんそのディレクトリにアクセス権限は必要だが。
  • id:wdc
    id:b-wind さん

    >>httpd.conf の DocumentRoot より上には行けないですよ。
    >それは違うでしょ。
    突っ込みありがとうございます。
    うちのサーバではディレクトリリスティングを無効にしていること、
    および<Directory />内で


    Order deny,allow
    Deny from all


    にしていることを失念していましたっ!
    この部分訂正させていただきます。

この質問への反応(ブックマークコメント)

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません