Fedora 11
Sponsored Link

バーチャルホストの設定2009/06/14

  バーチャルホストの設定をします。 ここの例では以下のような条件で設定します。

メインホスト www1.server-world.info
[ /var/www/html ]

追加ホスト  www1.virtual.host
[ /home/fedora/public_html ]


設定にあたっては、追加使用するホストのドメイン名も前もってDNSに登録しておく必要があります。

[1] Apache にバーチャルホストの設定をします。
[root@www1 ~]#
vi /etc/httpd/conf/httpd.conf


# 975行目:コメント解除

NameVirtualHost *:80

# 最終行:以下7行元ドメイン用追記

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName www1.srv.world
   ErrorLog logs/srv.world-error_log
   CustomLog logs/srv.world-access_log common
</VirtualHost>


# 最終行:以下6行追加ドメイン用追記

<VirtualHost *:80>
   DocumentRoot /home/fedora/public_html
   ServerName www1.virtual.host
   ErrorLog logs/virtual.host-error_log
   CustomLog logs/virtual.host-access_log common
</VirtualHost>


[root@www ~]#
/etc/rc.d/init.d/httpd restart

Stopping httpd:
[  OK  ]

Starting httpd:
[  OK  ]

[2] httpd 設定で作成した元ドメイン「server-linux」の テストページにアクセスしてバーチャルホストが効いているか動作確認してみます。 以下のようなページが表示されればOKです。
 
[3] 追加ドメイン「virtual.host」用のテストページを作成し、アクセスしてバーチャルホストが効いているか動作確認してみます。 以下のようなページが表示されればOKです。
[root@www1 ~]#
cd /home/fedora/public_html

[root@www1 public_html]#
vi index.html


<html>
<body>
<div style="width:100%;font-size:40px;font-weight:bold;text-align:center">
Virtual Host Test Page
</div>
</body>
</html>
関連コンテンツ