Tips記事
» 2001年05月30日 00時00分 UPDATE

1つのIPアドレスで複数のドメインを稼動させたい

[木田佳克,ITmedia]

 多くのレンタルサーバでは,1台のサーバ(1つIPアドレス)で複数のドメイン名を共存させていることが多い。

 それぞれのドメイン名でのDNSを設定し,Apacheでバーチャルホストの設定をすれば幾つものドメインを共存させることができる。手順は次の通りである(DNSが正常に動作していることが前提)。

1. 「/etc/named.conf」でバーチャルドメインのZONEファイルを指定する

# vi /etc/named.conf

〜中略〜

zone "xxxxxx.jp" {
    type master;
    file "xxxxx.jp.zone";
};

〜後略〜

2. バーチャルドメインのZONEファイルを用意する

 例として,次のようなZONEファイル(/var/named/xxxxx.jp.zone)を作成する。

@       IN   SOA   ns.xxxx.com. root.xxxx.com. (
            2001051301 ; Serial
            86400   ; Refresh
            10800   ; Retry
            604800   ; Expire
            259200   ; Minimum
            )
;name server
            NS   ns.xxxx.com.
            NS   ns2.xxxx.ne.jp.
@        IN   MX 10  ns.xxxx.com.
localhost        A    127.0.0.1
@            A    210.xxx.xxx.xxx
www           A    210.xxx.xxx.xxx

 ZONEファイルの作成個所(ディレクトリ先)は,named.confの中で次のように「options」の内容で分かる。ここでは,/var/named/となっている。

options {
    directory "/var/named";
};

3. 「/etc/httpd/conf/httpd.conf」ファイルの中でバーチャルホストの設定を加える

 httpdも動作させたい場合には,Apacheの設定ファイル(httpd.conf)にも手を加えよう。

NameVirtualHost 210.xxx.xxx.xxx

  ServerAdmin webmaster@xxxxx.jp
  DocumentRoot /home/xxxxxx/xxxxx_public_html
  ServerName www.xxxxx.jp
  ServerAlias xxxxx.jp
  UserDir disabled
  ErrorLog /var/log/httpd/xxxxx-error_log
  CustomLog /var/log/httpd/xxxxx-referer_log referer
  CustomLog /var/log/httpd/xxxxx-agent_log agent
  CustomLog /var/log/httpd/xxxxx-access_log combined

Copyright © ITmedia, Inc. All Rights Reserved.

注目のテーマ