tomo.gif (1144 ツバツイツト)line.gif (927 ツバツイツト)line.gif (927 ツバツイツト)To previous pageTo home pageMailing to me

ひとつのIPアドレスで複数のサイト名を使う

Modified: 1 May 2003

ひとつのIPアドレスで複数のサイト名を使うことを、ネームベース(名前ベース)の仮想ホストといいます。


元の"httpd.conf"

"httpd.conf"に、"Use name-based virtual hosting"と書かれたセクションを探します。

インストール直後には、以下のように、記述例がコメントとして書かれています。

     :
     :
### Section 3: Virtual Hosts
#
# VirtualHost: 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://www.apache.org/docs/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 *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

#<VirtualHost _default_:*>
#</VirtualHost>
     :


2つの名前ベースの仮想ホストを定義する

ベースとなっているサイト名

仮想のサイト名

ベースの設定を無効にする

<VirtualHost>として設定すると、もともと記述していた設定も有効ですが、混乱するので、で囲まれていない"ServerName"は、localhostにして、"DocumentRoot"はコメントにしておきましょう。

VirtualHostを設定する

ベースとなっているサイト定義を含めて、仮想のサイトを設定します。

        :
        :
ServerName   localhost
        :
        :
# DocumentRoot   "/var/www/html"
        :
        :
#
# Use name-based virtual hosting.
#

NameVirtualHost rh73-32.tomo.ac

<VirtualHost rh73-32.tomo.ac>
    ServerAdmin tomo@tomo.ac
    DocumentRoot /var/www/html
    ServerName rh73-32.tomo.ac
    ErrorLog  logs/rh73-32.tomo.ac-error_log
    CustomLog logs/rh73-32.tomo.ac-access_log common
</VirtualHost>

<VirtualHost rh73-32.tomo.ac>
    ServerAdmin tomo@tomo.ac
    DocumentRoot /var/www/html/host1.tomo.ac
    ServerName host1.tomo.ac
    ErrorLog  logs/host1.tomo.ac-error_log
    CustomLog logs/host1.tomo.ac-access_log common
</VirtualHost>

<VirtualHost rh73-32.tomo.ac>
    ServerAdmin tomo@tomo.ac
    DocumentRoot /var/www/html/host2.tomo.ac
    ServerName host2.tomo.ac
    ErrorLog  logs/host2.tomo.ac-error_log
    CustomLog logs/host2.tomo.ac-access_log common
</VirtualHost>

       :
       :


DNSに設定を追加する

仮想ホストのサイト名を、実サーバーであることを知らせるために、CNAMEで登録します。

        :
        :
host1           IN  CNAME       rh73-32.tomo.ac.
host2           IN  CNAME       rh73-32.tomo.ac.
        :
        :

 "rh73-32.tomo.ac."の最後の、"."を忘れないように気をつけてください。忘れると名前が解決できません。


To previous pageTo home pageMailing to meJump to Top of pageline.gif (927 ツバツイツト)tomo.gif (1144 ツバツイツト)