環境:CentOS 5 64bit
Apache:2.x
やりたいこと:example.comとtest.example.comを自宅サーバ(Apache)へリレーし、Apacheのバーチャルホストでそれぞれ別のディレクトリ配下を表示させる。
前提:DDNSはeverydnsを利用し以下のように設定済み。
example.com A [自分のグローバルIPアドレス]
test.example.com CNAME example.com
- conf/httpd.confの編集
- conf/extra/httpd-vhosts.confの編集
- ユーザディレクトリの作成
- httpd再起動
- example.comとtest.example.comがそれぞれ表示されればOK ※あらかじめ、それぞれのDocumentRootに識別可能な形のindex.htmlを置いておくこと
$ vi httpd.conf
#Include conf/extra/httpd-vhosts.conf
↓ (コメントを排除)
Include conf/extra/httpd-vhosts.conf$ vi httpd-vhosts.conf
# ローカルIPアドレスを指定
NameVirtualHost 192.168.xxx.xxx:80
# example.comの設定
<VirtualHost 192.168.xxx.xxx:80>
ServerAdmin webmaster@example.com
DocumentRoot "/usr/local/apache2/htdocs"
ServerName example.com # 自分のドメイン
ServerAlias www.example.com # alias
ErrorLog "logs/example.com-error_log"
CustomLog "logs/example.com-access_log" common
</VirtualHost>
# test.exampleの設定
<VirtualHost 192.168.xxx.xxx:80>
ServerAdmin webmaster@example.com
DocumentRoot "/home/test" # 今回はユーザディレクトリをドキュメントルートとする
ServerName test.example.com
ErrorLog "logs/test.example.com-error_log"
CustomLog "logs/test.example.com-access_log" common
# ユーザディレクトリにアクセス権を付与
<Directory "/home/test">
Options FollowSymLinks
AllowOverride all # .htaccess有効化
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
$ useradd test
$ passwd test
$ chown test:httpd test ★グループをApacheの実行ユーザと同じにする
$ chmod 710 test ★Apacheの実行ユーザがユーザディレクトリを実行できるようにする
$ /etc/rc.d/init.d/httpd restart以上
関連するかもしれない記事
- Apache mod_rewriteをDSOで有効化
- Apache 仮想ディレクトリの設定(Alias)
- linuxへのSubversionのインストール
- SendMail メール受信をトリガーにしてプロセスを起動
- php.iniの置き場所
他のブログも読む



0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.