====== SSL証明書の取得(Let's Encrypt) ====== $ sudo yum install epel-release $ sudo yum install -y certbot python-certbot-apache # 何も指定しない場合、ドメインを選択肢から選ぶ $ sudo certbot # 予めドメインを指定して、実行する場合 $ sudo certbot certonly --webroot -w /var/www/example.com -d example.com -d www.example.com $ sudo ls -la /etc/httpd/conf.d/ $ sudoedit /etc/httpd/conf.d/vhost-le-ssl.conf $ sudo ls -la /etc/letsencrypt/live/www.example.com/ # CN= の後ろがサーバ名と同じか確認 $ openssl x509 -in /etc/letsencrypt/archive/www.example.com/fullchain1.pem -noout -subject # バーチャルホストの設定を確認 $ sudoedit /etc/httpd/conf.d/vhost.conf # ssl用のバーチャルホストを設定 $ sudoedit /etc/httpd/conf.d/vhost-le-ssl.conf # logファイルに prefix「ssl_」をつける # wwwのあり・なしの統一(なしの場合の例) RewriteEngine on RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^ https://example.com%{REQUEST_URI} [END,NE,R=permanent] # 再起動 $ sudo apachectl graceful 各アドレスにアクセスし、想定通りの動きをするか確認。 ===== SSL でアクセスするとリダイレクト前に証明書エラーがでる場合 ===== 証明書が「www.example.com」もしくは「example.com」で発行した場合、発行しなかった方のドメインで「https://...」にアクセスすると証明書エラーが出てしまう。\\ Chrome では一見問題ないように見えて、デベロッパーツールの Console を見てみると以下のようなメッセージが表示される。 > Redirecting navigation www.example.com -> example.com because the server presented a certificate valid for example.com but not for www.example.com. To disable such redirects launch Chrome with the following flag: --disable-features=SSLCommonNameMismatchHandling この場合、証明書発行時にサブドメインも含めることで対処可能です。 # 証明書発行時に -d オプションでサブドメインも含めて指定すればOK $ sudo certbot certonly --webroot -w /var/www/example.com -d example.com -d www.example.com # 既存の証明証がある場合は、以下のように聞かれるので「E」を押してエンターすればOK Do you want to expand and replace this existing certificate with the new certificate? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (E)xpand/(C)ancel: # 再起動 $ sudo apachectl graceful 再度サイトにアクセスして問題ないことを確認します。