*** バーチャルホストを試してみる [#s2b2a147]
- バーチャルホストの設定方法としては、「IPベース」「Nameベース」「ポートベース」があります。ここでは、Nameベースで設定したのでその説明。
- ここでやりたいこと
1. サブドメインによるアクセス切り替え
2. マルチドメイン対応
-- サブドメインや、マルチドメインの設定は bind による[[事前準備>http://www.sea-bird.org/pukiwiki/index.php?CentOS6%20%2F%20BIND%A4%CE%C0%DF%C4%EA%A4%CE%B4%AC]]が必要です。
*** サブドメインによるアクセス切り替え [#jae5d3ef]
- COLOR(RED){''/etc/httpd/conf/httpd.conf''} 以下の定義値を修正または追加する。
#ServerName www.example.com:80 ← コメントにする
NameVirtualHost *:80 ← コメントを解除
- COLOR(RED){''/etc/httpd/conf.d/virtualhost-sea-bird.org.conf''} と、ファイルを作成します。
#
# Use name-based virtual hosting.
#
<VirtualHost *:80> ← 1.
ServerAdmin hoge@sea-bird.org
DocumentRoot "/var/www/html"
ServerName www.sea-bird.org
ErrorLog logs/error_log
CustomLog logs/access_log combined
</VirtualHost>
<VirtualHost *:80> ← 2.
ServerAdmin hoge@sea-bird.org
DocumentRoot "/var/www/html/blog"
ServerName blog.sea-bird.org
ErrorLog logs/error_log
CustomLog logs/access_log combined
</VirtualHost>
<VirtualHost *:80> ← 3.
ServerAdmin hoge@sea-bird.org
DocumentRoot "/var/www/html/hoge"
ServerName test.sea-bird.org
ErrorLog logs/error_log
CustomLog logs/access_log combined
</VirtualHost>
- サーバを再起動します
# /etc/init.d/httpd restart
# httpd -S
-- 上記の設定の意味は以下の通りです
1.www.sea-bird.org にアクセスがあった場合、ドキュメントルートを "/var/www/html" に
2.blog.sea-bird.org にアクセスがあった場合、ドキュメントルートを "/var/www/html/blog" に
3.hoge.sea-bird.org にアクセスがあった場合、ドキュメントルートを "/var/www/html/hoge" に
*** マルチドメイン対応 [#ecbe247f]
- mcbc-net.net ドメインも所有しているので同じサーバでルチドメイン対応をしてみる。といっても、ServerName に ドメインを記述するだけでok
- COLOR(RED){''/etc/httpd/conf.d/virtualhost-mcbc-net.net.conf''} とでも、ファイルを作成します。
#
# Use name-based virtual hosting.
#
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName www.mcbc-net.net
</VirtualHost>
*** 参考にさせて頂いたサイト様 [#z6fef845]
-- [[バーチャルホスト設定(Apache)>http://centossrv.com/apache-virtualhost.shtml]]
-- [[IPベースのバーチャルホスト(内部検証用)|CentOS>http://blog.sugulab.com/?p=1574]]