Home > Webサーバー Archive

Webサーバー Archive

Apache2.0でポート毎にサイト環境を作る方法(※要するに仮想環境)

サーバで「ルートから辿る」記述をしているHTMLソースを、そっくりそのまま自分のマシン上で動かす必要があったので調べてみました。

【要件】
・Apache2.0
・同一のIP、複数ポートをリスン
・ポート毎に異なるDocumentRoot

要は、やりたい事はこれ。
http://httpd.apache.org/docs/2.2/ja/vhosts/examples.html#port

でもこのドキュメント、Apache2.2系の解説なんだよなー。。。

とか思いながらApache2.0のhttpd.confを見てたらこんなくだりを発見。(httpd.confの一番最後)

<引用>
#
# 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.
#
#
# 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
#

意外と簡単そうじゃないかと。
早速、Example通りに追記してみる。

//////////

ServerAdmin webmaster@dummy-host.example.com
DocumentRoot “D:\www\tr-lab\itshindan”
ServerName itshindan.jp:81
ErrorLog logs/itshindan-error_log
CustomLog logs/itshindan-access_log common

//////////

あとはリスンポートの設定にポート81を追記。
オイラのマシンでは元々ポート80をリスンしていたので下のようになる。

//////////
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 80
Listen 81 (←今回追記した部分)
//////////

この2つの追記を行ってApacheをリスタート。
無事に各ポートでリスンしてくれました。

ちなみにポート82を追加しても動きました。
どこまで増やして大丈夫かはマシンパワーに依存するのかな。。。?

Home > Webサーバー Archive

Search
Feeds
Meta

Return to page top