★Apache : httpd
バーチャルホストの使い方.
yaguma.ath.cxのドキュメントルートを/home/httpd/httpdocsへ
abc.zive.netのドキュメントルートを/home/httpd/httpdocs/abcとする場合下記のようなスクリプトにする.abc.zive.netでは/home/httpd/httpdocs/abc/index.htmlが表示されるようになる.
ちなみにdyndns.orgのyaguma.ath.cxはワイルドカードが使えるのでバーチャルホストはとても便利です.
つまりabc.yaguma.ath.cxやefg.yaguma.ath.cxをバーチャルホストに定義づけられます.
/etc/httpd/conf/httpd.conf
------- 省略 ----------
DocumentRoot /home/httpd/httpdocs
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/httpd/httpdocs>
Options Includes FollowSymLinks <- Indexesを消す.これによってディレクトリ内の一覧表示ができなくなる
AllowOverride All <- htmlの置いてあるディレクトリで.htaccessが使えるようになる.
Order allow,deny
Allow from all
</Directory>
------- 省略 ----------
NameVirtualHost 192.168.1.102 <- ルータがある場合はサーバ機のプライベートアドレスにする.もしくは*でもかまわない.
<VirtualHost 192.168.1.102>
DocumentRoot /home/httpd/httpdocs
ServerName www.yaguma.ath.cx
</VirtualHost>
<VirtualHost 192.168.1.102>
DocumentRoot /home/httpd/httpdocs
ServerName yaguma.ath.cx
</VirtualHost>
<VirtualHost 192.168.1.102>
DocumentRoot /home/httpd/httpdocs/abc
ServerName abc.zive.net
</VirtualHost>
---- ここまで
上記はルートからのものですが,ルート以外のユーザをバーチャルホストとするためには次のようにします.(vine
linuxのapacheによるルートは/home/httpdですが,Red Hatなどは/varディレクトリに作られているかも知れません)
例えばtaroというユーザを作ります.
# useradd -g homeuser taro
# passwd taro
ここでもしSambaを使ってWindowsと連係するならWindows側と同じユーザ名とパスワードを指定します.またグループ名がhomeuserですが,これはProFTPでログインできるグループ名としました.(ProFTPの項を参照)
ユーザtaroのホームディレクトリは/home/taroです.ここにhtmlファイルを置くhttpdocsディレクトリを作ります.このディレクトリは自分の好きなもので構いません.パーミッションは755とします.
$ mkdir /home/taro/httpdocs
$ chmod 755 httpdocs
以下のようにhttpd.confを改変します.
/etc/httpd/conf/httpd.conf
--- 省略
<Directory /home/httpd/httpdocs>
Options Includes FollowSymLinks <- Indexesを消す.これによってディレクトリ内の一覧表示ができなくなる
AllowOverride All <- htmlの置いてあるディレクトリで.htaccessが使えるようになる.
Order allow,deny
Allow from all
</Directory>
#付け足す部分
<Directory /home/taro/httpdocs>
Options Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
----- 省略
NameVirtualHost 192.168.1.102 <- ルータがある場合はプライベートアドレスにする事
<VirtualHost 192.168.1.102>
DocumentRoot /home/httpd/httpdocs
ServerName www.yaguma.ath.cx
</VirtualHost>
<VirtualHost 192.168.1.102>
DocumentRoot /home/httpd/httpdocs
ServerName yaguma.ath.cx
</VirtualHost>
<VirtualHost 192.168.1.102>
DocumentRoot /home/httpd/httpdocs/abc
ServerName abc.zive.net
</VirtualHost>
# 付け足す部分 ユーザtaroはtaro.zive.netというドメイン名を持っているとします.
<VirtualHost 192.168.1.102>
DocumentRoot /home/taro/httpdocs
ServerName taro.zive.net
</VirtualHost>
----- ここまで
httpd.confを改変したら # service httpd restart もしくは # /etc/rc.d/init.d/httpd restartを忘れずに.
これで普通のユーザにもホームページが使えるようになります.友人のホームページ枠を作ってあげる事もできます.
ちなみに私は以下のような.htaccessファイルを使ってhtmlファイルでcgi,ssiを使えるようにしています.(上記の例では/home/taro/httpdocsに.htaccessを置く)
.htaccess
Options ExecCGI Includes
AddType text/x-server-parsed-html .shtml .html
AddHandler server-parsed .shtml
AddType text/css .css
AddType application/x-httpd-cgi .cgi .pl
DirectoryIndex index.html index.htm
Copyright 2002-2003 Kai All Rights Reserved & This site is Link Free
戻る