GoogleがやたらとSSL対応を勧めてくるんですよ。
やっぱり今後はSSL対応が必須になる時代が来そうです。
でもSSLって高いイメージがあるし、証明書の更新も面倒。
今の時代無料でできねーかなと調べてみたらなんかできそうな雰囲気。
また時間がある時にトライしてみます。
Let's Encrypt で無料でSSLが導入できるようです。
証明書の発行・インストール・更新のプロセスを自動化できるようです。
制限があります。
https://letsencrypt.org/docs/rate-limits/
参考
# wget https://dl.eff.org/certbot-auto # chmod 700 certbot-auto
ヘルプは以下で確認できます。
# ./certbot-auto --help
以下を実行すると、自動的にyumが実行され、必要なパッケージがインストールされます。
# ./certbot-auto
CentOS6.2ではyumにて python-pip-1.3.1-4.el6.noarch がダウンロードできずにエラーになってしまいました。
epelリポジトリを入れるとハマるみたいです。
設定を書き換えます。
# vi /etc/yum.repos.d/epel.repo
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
↓
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
同一サーバで別ドメインの証明書を取得する場合は、443ポートがすでに稼働しているために取得が完了できません。
そのため開始前にWEBサーバを止めておきます。
また、メールアドレスの入力と同意の設問はスキップされます。
# ./certbot-auto certonly
How would you like to authenticate with the ACME CA? ------------------------------------------------------------------------------- 1: Place files in webroot directory (webroot) 2: Spin up a temporary webserver (standalone) ------------------------------------------------------------------------------- Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
2を入力
※certbot-autoのバージョンが上がって順番が入れ替わっている場合があるので注意が必要です。
Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel):
メールアドレスを入力
------------------------------------------------------------------------------- Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree in order to register with the ACME server at https://acme-v01.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel:
Aを入力
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel):
証明書を導入したいドメインをカンマもしくはスペース区切りで入力
成功すれば /etc/letsencrypt/archive/ドメイン/ 以下に4ファイル生成されます。
数字は更新するたびにインクリメントされるようです。
シンボリックリンクが以下に作成されるので、WEBサーバへの設定は以下を指定します。
Apache 2.4.8未満では公開鍵、中間証明書、秘密鍵を使用します。
それ以上やNginxではサーバ証明書と中間証明書が結合されたファイル、秘密鍵を使用します。
ソースでインストールしている場合は --enable-ssl が有効になっているか確認。
以下の行があるか確認します。
LoadModule ssl_module modules/mod_ssl.so
以下をApacheの設定ファイルに追加します。
Apache 2.4.8未満の場合
Listen 443 <VirtualHost *:443> ServerName ドメイン:443 DocumentRoot "/home/ドメイン/public_html" SSLEngine on SSLHonorCipherOrder on Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile /etc/letsencrypt/live/ドメイン/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/ドメイン/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/ドメイン/chain.pem <Directory "/home/ドメイン/public_html"> Options FollowSymLinks AllowOverride ALL Require all granted </Directory> ErrorLog "logs/ssl_error_log" CustomLog "logs/ssl_access_log" combined </VirtualHost>
Apache 2.4.8以降の場合
<VirtualHost *:443> ServerName ドメイン:443 DocumentRoot "/home/ドメイン/public_html" SSLEngine on SSLHonorCipherOrder on Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2 SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 SSLCertificateFile /etc/letsencrypt/live/ドメイン/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/ドメイン/privkey.pem <Directory "/home/ドメイン/public_html"> Options FollowSymLinks AllowOverride ALL Require all granted </Directory> ErrorLog "logs/ssl_error_log" CustomLog "logs/ssl_access_log" combined </VirtualHost>
.htaccessを設置してhttpにアクセスがあった場合はhttpsへそのまま転送させます。
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
crontabに登録しておくことで自動更新が可能です。
毎月1日午前9時に一括更新する場合
0 9 1 * * /etc/rc.d/init.d/httpd stop && /pathto/certbot-auto renew --force-renew && /etc/rc.d/init.d/httpd start
毎月1日午前9時に特定のドメインを更新する場合
0 9 1 * * /etc/rc.d/init.d/httpd stop && /pathto/certbot-auto certonly --standalone -d example.com -d example2.com --renew-by-default && /etc/rc.d/init.d/httpd start
ログは /var/log/letsencrypt/letsencrypt.log に出力されています。
# ./certbot-auto certificates
------------------------------------------------------------------------------- Found the following certs: Certificate Name: example.com Domains: example.com Expiry Date: 2017-08-22 23:01:00+00:00 (VALID: 55 days) Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem -------------------------------------------------------------------------------