====== Apache SSL での VirtualHost、SNI、Redirect の設定 ====== ===== 実現したい仕様 ===== 複数の SSL ドメインを 1台の Web サーバーでホスティングし、且つ、すべてのユーザーアクセスパターンをドメイン毎に単一バーチャルホストへリダイレクトするための設定を実現する。\\ Server Name Indication(SNI) を利用する事で、1台の Web サーバーで複数の SSL ドメインをホスティングする事ができる。\\ SNI 利用するには以下の条件が必要である。\\ * Apache 2.2.12 以降 * 複数の SSL 証明書を取得済みである事 ^ ユーザーアクセスパターン ^ Apache の動作 ^ | http://monsters-g.com | https://www.monsters-g.com へリダイレクト | | http://www.monsters-g.com | https://www.monsters-g.com へリダイレクト | | https://monsters-g.com | https://www.monsters-g.com へリダイレクト | | http://tomoyan.net | https://www.tomoyan.net へリダイレクト | | http://www.tomoyan.net | https://www.tomoyan.net へリダイレクト | | https://tomoyan.net | https://www.tomoyan.net へリダイレクト | | http://repos.tomoyan.net | https://repos.tomoyan.net へリダイレクト | ===== 最終的な設定内容(問題の発生しない設定) ===== Apache は Rewrite より Redirect の方が処理としては軽い。\\ Rewrite するだけの処理であったとしても SSL の証明書の指定は必要である。もしも証明書を指定しなかった場合は、全体的に原因不明な変な動作を引き起こした。\\ ==== Apache 全体の SSL の設定 ==== $ sudo vi /etc/httpd/conf.d/ssl.conf # SNIに未対応のブラウザ用の設定 SSLStrictSNIVHostCheck off ==== monsters-g.com SSL の設定 ==== Apache のバーチャルホストの設定。\\ $ sudo vi /etc/httpd/conf.d/www.monsters-g.com.conf ServerName www.monsters-g.com ServerAlias monsters-g.com Redirect "/" "https://www.monsters-g.com/" DocumentRoot "/var/www/vhosts/www.monsters-g.com" ServerName www.monsters-g.com ServerAlias monsters-g.com RewriteEngine on RewriteCond %{HTTP_HOST} ^monsters-g\.com RewriteRule ^/(.*)$ https://www.monsters-g.com/$1 [R=301,L] SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite !3DES:!aNULL:EDH+HIGH:ECDH+HIGH:-AES128:-3DES:-DSS:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA SSLHonorCipherOrder on SSLCertificateFile /etc/letsencrypt/live/monsters-g.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/monsters-g.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/monsters-g.com/chain.pem Require all granted Options All AllowOverride All DirectoryIndex index.php index.html ==== tomoyan.net SSL の設定 ==== $ sudo vi /etc/httpd/conf.d/www.tomoyan.net.conf ServerName www.tomoyan.net ServerAlias tomoyan.net Redirect "/" "https://www.tomoyan.net/" DocumentRoot "/var/www/vhosts/www.tomoyan.net/dokuwiki" ServerName www.tomoyan.net ServerAlias tomoyan.net RewriteEngine on RewriteCond %{HTTP_HOST} ^tomoyan\.net RewriteRule ^/(.*)$ https://www.tomoyan.net/$1 [R=301,L] SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite !3DES:!aNULL:EDH+HIGH:ECDH+HIGH:-AES128:-3DES:-DSS:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA SSLHonorCipherOrder on SSLCertificateFile /etc/letsencrypt/live/tomoyan.net/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/tomoyan.net/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/tomoyan.net/chain.pem Require all granted Options All AllowOverride All DirectoryIndex index.php index.html ==== repos.tomoyan.net SSL の設定 ==== Apache のバーチャルホストの設定。\\ $ sudo vi /etc/httpd/conf.d/repos.tomoyan.net.conf ServerName repos.tomoyan.net Redirect "/" "https://repos.tomoyan.net/" DocumentRoot "/var/www/vhosts/repos.tomoyan.net" ServerName repos.tomoyan.net SSLEngine on SSLProtocol all -SSLv2 -SSLv3 SSLCipherSuite !3DES:!aNULL:EDH+HIGH:ECDH+HIGH:-AES128:-3DES:-DSS:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA SSLHonorCipherOrder on SSLCertificateFile /etc/letsencrypt/live/tomoyan.net/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/tomoyan.net/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/tomoyan.net/chain.pem Require all granted Options All AllowOverride All DirectoryIndex index.php index.html ===== 最初の設定内容(問題の発生する設定) ===== 結論から言うと以下の設定方法では問題が発生しました。\\ なぜか https://monsters-g.com のユーザーアクセスパターンの時だけ、Apache が tomoyan.net の SSL 証明書を使って通信を暗号化しようとする現象が発生し、原因不明で悩みました。 ==== Apache 全体の SSL の設定 ==== $ sudo vi /etc/httpd/conf.d/ssl.conf # SNIに未対応のブラウザ用の設定 SSLStrictSNIVHostCheck off ==== monsters-g.com SSL の設定(問題の発生する設定) ==== $ sudo vi /etc/httpd/conf.d/www.monsters-g.com.conf ServerName monsters-g.com RewriteEngine on RewriteCond %{HTTP_HOST} ^monsters-g\.com RewriteRule ^/(.*)$ https://www.monsters-g.com/$1 [R=301,L] ServerName www.monsters-g.com RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.monsters-g\.com RewriteRule ^/(.*)$ https://www.monsters-g.com/$1 [R=301,L] DocumentRoot "/var/www/vhosts/www.monsters-g.com" ServerName www.monsters-g.com SSLCertificateFile /etc/letsencrypt/live/monsters-g.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/monsters-g.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/monsters-g.com/chain.pem Require all granted Options All AllowOverride All DirectoryIndex index.php index.html ==== tomoyan.net SSL の設定(問題の発生する設定) ==== $ sudo vi /etc/httpd/conf.d/www.tomoyan.net.conf ServerName tomoyan.net RewriteEngine on RewriteCond %{HTTP_HOST} ^tomoyan\.net RewriteRule ^/(.*)$ https://www.tomoyan.net/$1 [R=301,L] ServerName www.tomoyan.net RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.tomoyan\.net RewriteRule ^/(.*)$ https://www.tomoyan.net/$1 [R=301,L] DocumentRoot "/var/www/vhosts/www.tomoyan.net/dokuwiki" ServerName www.tomoyan.net SSLCertificateFile /etc/letsencrypt/live/tomoyan.net/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/tomoyan.net/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/tomoyan.net/chain.pem Require all granted Options All AllowOverride All DirectoryIndex index.php index.html ==== repos.tomoyan.net SSL の設定(問題の発生する設定) ==== $ sudo vi /etc/httpd/conf.d/repos.tomoyan.net.conf ServerName repos.tomoyan.net RewriteEngine on RewriteCond %{HTTP_HOST} ^repos\.tomoyan\.net RewriteRule ^/(.*)$ https://repos.tomoyan.net/$1 [R=301,L] DocumentRoot "/var/www/vhosts/repos.tomoyan.net" ServerName repos.tomoyan.net SSLCertificateFile /etc/letsencrypt/live/tomoyan.net/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/tomoyan.net/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/tomoyan.net/chain.pem Require all granted Options All AllowOverride All DirectoryIndex index.php index.html ===== 参考文献 ===== [[https://wiz-code.net/linux/install/diary/24_apache_virtualhost.html|Apache VirtualHostとSNIの設定 - StudioAREA.WIZ]]\\ [[http://www.neobit.jp/archives/232|Alias Redirect Rewrite~の使い分け | 技術屋ネオビットの覚え書き]]\\ [[https://blog.apar.jp/linux/378/|名前ベースのバーチャルホストでSSLを使う(SNI) | あぱーブログ]]\\ [[https://qiita.com/papillon/items/f56a6f278609270a392c|mod_sslで使用するSSLCipherSuiteの設定を詰めてみる - Qiita]]\\ [[http://www.nina.jp/server/redhat/httpd/httpd_conf.html|もっとhttpd.confの設定]]\\ [[http://www.orangetakam.com/blog/archives/122|CentOS7 HTTPサーバ2.4系でアクセスの許可と拒否の書き方]]\\