後々のことを考慮し最初から仮想サーバとして運用(/home/taro/public_html にコンテンツを配置する http://www.mydomain/~taro/ とはしない)。
アクセスログ・エラーログは仮想サーバ毎に出力。
アクセスログ・エラーログは仮想サーバ毎に出力。
/home /home/taro /home/taro/web /home/taro/web/domain1 /home/taro/web/domain1/appli ← CGI等 /home/taro/web/domain1/document ← ドキュメントルート /home/taro/web/domain1/logs ← ログ仮想サーバを追加する場合
/home/taro/web/domain2 /home/taro/web/domain2/appli /home/taro/web/domain2/document /home/taro/web/domain2/logsあるいは
/home/jiro/web/domain3 /home/jiro/web/domain3/appli /home/jiro/web/domain3/document /home/jiro/web/domain3/logs という具合。手順は ▼
●apache グループユーザに新規ファイルの書き込み権限を与える。ゲストユーザは Read、Write 禁止。
/etc/profile.d へ次のシェルを追加することで、次回のログインから反映。
/etc/profile.d へ次のシェルを追加することで、次回のログインから反映。
[root@www ~]# vi /etc/profile.d/mybashrc.sh if [ "`id -gn`" = "apache" ]; then umask 0007 fi●ルート権限から抜けてフォルダを作成
[taro@www ~]$ mkdir ~/web [taro@www ~]$ mkdir ~/web/domain [taro@www ~]$ mkdir ~/web/domain/appli [taro@www ~]$ mkdir ~/web/domain/document [taro@www ~]$ mkdir ~/web/domain/logs●再びルート権限となり
[root@www ~]# ll /home 合計 8 drwx------ 5 taro apache 4096 5月 29 19:34 taro このディレクトリに実行権限を付与するとブラウザで閲覧可能。 [root@www ~]# chmod o+x /home/taro あるいは [root@www ~]# chmod 711 /home/taro●名前ベースで仮想サーバを1つ追加する基本設定
[root@www ~]# mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org [root@www ~]# cp /etc/httpd/conf/httpd.conf.org /etc/httpd/conf/httpd.conf [root@www ~]# vi /etc/httpd/conf/httpd.conf [root@www ~]# diff /etc/httpd/conf/httpd.conf.org /etc/httpd/conf/httpd.conf 972c972 < #NameVirtualHost *:80 --- > NameVirtualHost *:80 991a992,999 > <VirtualHost *:80> > ServerAdmin root@localhost > DocumentRoot /home/taro/web/domain1/document > ServerName www.mydomain > ServerAlias mydomainA *.mydomain > ErrorLog /home/taro/web/domain1/logs/error_log > CustomLog /home/taro/web/domain1/logs/access_log combined > </VirtualHost>2つ目以降は
<VirtualHost *:80> ServerAdmin root@localhost DocumentRoot /home/taro/web/domain2/document ServerName www.mydomainB ServerAlias mydomainB *.mydomainB ErrorLog /home/taro/web/domain2/logs/error_log CustomLog /home/taro/web/domain2/logs/access_log combined </VirtualHost> を続けて追加。●設定ファイルの文法チェック
[root@www ~]# /usr/sbin/apachectl configtest Syntax OK●再起動
[root@www ~]# service httpd startここまでの設定だけで、スタティックコンテンツ閲覧やphp実行が可能。