Let's Encrypt で SSL 化
https://letsencrypt.jp/:日本語のマニュアルサイトがあるので簡単だった。
それぞれのOSのパッケージがあるとおもうので、そこからインストールする
# python2 --version Python 2.7.13 # pkg search certbot py27-certbot-0.21.0,1 Let's Encrypt client py36-certbot-0.21.0,1 Let's Encrypt client' # pkg install py27-certbot ---- (中略) ---- This port installs the "standalone" client only, which does not use and is not the certbot-auto bootstrap/wrapper script. The simplest form of usage to obtain certificates is: # sudo certbot certonly --standalone -d <domain>, [domain2, ... domainN]>
ということで、パッケージからインストールしたときには、certbot-auto スクリプトは使用せず、standalone モードで使用する。
certbot-auto なら、ウェブサーバの設定もしてくれるのでそっちのほうが楽だったぞ…
standalone モードでは port 80, 443 が開いていないと
Problem binding to port 80: Could not bind to IPv4 or IPv6.
と怒られるので、apache などが動いているのなら、一旦停止させる。
# certbot certonly --standalone -d example.net Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): hoge@example.net ← 初回のみメールアドレスを入力 (A)gree/(C)ancel: a ← 使用許諾への同意 (Y)es/(N)o: n ← Electronic Frontier Foundation のMLへ参加するかどうか
証明書が /usr/local/etc/letsencrypt/live/example.net/cert.pem に
プライベートキーが /usr/local/etc/letsencrypt/live/kyo-to.net/privkey.pem に
保存される。
すでにhttpで公開していたのなら、mod_rewrite で http へのアクセスを https へ転送するために、ホストディレクティブに転送設定を追加して、
RewriteEngine on RewriteCond %{SERVER_NAME} =example.jp RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,NE,R=permanent]
ssl.conf に証明書の設定をする
SSLCertificateFile /usr/local/etc/letsencrypt/live/example.net/cert.pem SSLCertificateKeyFile /usr/local/etc/letsencrypt/live/example.net/privkey.pem SSLCertificateChainFile /usr/local/etc/letsencrypt/live/example.net/chain.pem
証明書の更新
Let's Encrypt の証明書は3ヶ月なので、期限が来るまでに更新が必要。
更新は
# certbot renew
とするだけ、cron で1月更新くらいに設定しておくといい