apacheにVirtualHostとSSLの設定をします。
手順としては、
- SSLの導入
- VirtualHostの設定
- SSLの設定
- apacheの設定反映
となります。
SSLの導入と設定
mod_sslとopensslをyumでインストールします。
yum -y install mod_ssl openssl
ベリサインなどのちゃんとした認証局を利用する場合、CSRの生成とか、発行してもらった証明書の設置を行います。
オレオレ認証であれば、証明書関係の設定は不要です。
VirtualHostの設定
/etc/httpd/conf/httpd.conf
で、末尾にある、
#NameVirtualHost *:80
と
#<VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com # DocumentRoot /www/docs/dummy-host.example.com # ServerName dummy-host.example.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost>
の設定を変更します。
例えば、IPが「123.123.123.123」でドメインが「site2.example.com」なら
NameVirtualHost 123.123.123.123:80 <VirtualHost 123.123.123.123:80> ServerAdmin webmaster@example.com DocumentRoot /www/docs/site2.example.com ServerName site2.example.com ErrorLog logs/site2.example.com-error_log CustomLog logs/site2.example.com-access_log common </VirtualHost>
のような感じです。
SSLの設定
/etc/httpd/conf.d/ssl.conf
の
<VirtualHost _default_:443>
となっているところを
#<VirtualHost _default_:443> NameVirtualHost 123.123.123.123:443 <VirtualHost 123.123.123.123:443>
に変更。また
#DocumentRoot "/var/www/html" #ServerName www.example.com:443
のところを
DocumentRoot "/www/docs/site2.example.com" ServerName site2.example.com
のような感じにする。
apacheの設定反映
/etc/rc.d/init.d/httpd restart
で再起動させれば完了です。
※参考1
virtual hostの設定の関係でhttpd起動時に
Starting httpd: [Mon Mar 26 19:29:31 2012] [error] VirtualHost 123.123.123.123:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
のようなエラーが出る場合は、
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/ssl.conf
でのNameVirtualHostの設定で、ポート番号の記述が統一されていないことが原因です。記述を統一し、再起動すると問題は解消されます。
※参考2
SSLにおいてもログの書式をhttpのような感じにするなら
/etc/httpd/conf.d/ssl.conf
の
LogLevel warn
のあとに
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
を追加するとよいです。
※参考3
iptablesで443ポートが開いていることも確認しましょう。