一つのWEBサーバで一つのサイトを公開するまでは、意外とすんなり行ける・・・はず。
一つのWEBサーバで複数サイトを公開しつつ、ローカルと外部のアクセスによってログを変えたり、入ってくるデバイスによって公開ページを変えたり等など始めると結構ややこしい。
まずは複数の例を見ながら理解&必要な点をコピペするのが早いと思う。
例
###WEBサーバマシンのアクセス受け付けアドレスとポート番号###
###debianにおいて、Listen行はports.confに書く###
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080
###各対応サイトの設定###
<VirtualHost 172.20.30.40:80>
##公開ディレクトリのroot##
DocumentRoot /www/example1-80
##要求ホスト名##
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
上記例は、かなり丁寧な設定になっている。
Listen行で受付IPアドレスとポート番号を指定し、各対応のIPアドレスとポート番号には一つのサイトURLが対応付けられている。
一つの”IPアドレスとポート番号(80が多いであろう)の組み合わせ”で複数サイトのアクセスを受け付ける場合、NameVirtualHost行が必要である。
例
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.co.jp
DocumentRoot /home/sitemaster/public_html/
</VirtualHost>
<VirtualHost *:80>
ServerName example222.co.jp
DocumentRoot /home/sitemaster222/public_html/
</VirtualHost>
ルータを介さず、linuxマシンがWANに直接接続しルータ兼用等の場合であれば、(DSLなどで接続しているpppデバイス等、IPアドレスが変化する場合)
Listen 80
NameVirtualHost *:80
以下 VirtualHost行
と設定。
VirtualHostの設定例集
http://httpd.apache.org/docs/2.0/ja/vhosts/examples.html
この記事へのコメント
コメントを書く
この記事へのトラックバックURL
http://blog.seesaa.jp/tb/41624641
この記事へのトラックバック
http://blog.seesaa.jp/tb/41624641
この記事へのトラックバック