サイトのSSL化(https化)は証明書を発行してもらってインストールして、期限前に更新して…と金銭的コストのみならず人的コストも大きかったのですが、世のSSL化と軌を一にして無償のSSL証明書取得スキームであるLet's Encrypt(以降LE)が出来て便利になりました。
というわけでLEを利用してサイトのSSL証明書を取得しhttps化する流れをまとめておきます。
パッケージの取得
確かこれで行けるはず。依存関係で必要なものがあれば自動的にやってくれます。
証明書の発行
これでまずは初回の証明書発行が行われます。
と聞かれるので、連絡が付くメールアドレスを入れます。
ライセンス条項ちゃんと読め。読んだな?と聞いているので、ちゃんと読んでからyを入力。
そうすると、次に
と聞かれるので、賛同するならyを入力。
その次は、
と言われるので、証明書を作成したいサイト(複数選択可)の番号を選択します。なお、この段階の前までにhttpでサイトにアクセスできる環境(DNS的にもね)が完成していないとダメだと思う。
HTTPS化したいサイトの番号を入力すると、
とか言われて無事証明書の作成と保存が完了します。なお、ここに掛かれてる通り、証明書の期限はそんなに長くないので、期限が切れる前に自動で更新するようにします。その辺りは後述。
Apacheの設定
Apache側の設定は二か所あります。
まず、/usr/local/etc/apache24/httpd.conf の中のsslモジュールに関するコメントアウトを外します。あと、443番をListenするようにします。
次はサイトの設定です。
VirtualHostを使わず運用している人もいるかと思いますが、今後の拡張を考えればVirtualHostの中にサイト設定突っ込んでいった方が良いです。
というか、httpとhttpsの両方を立てる時点でVirtualHostにしないとダメですしね。
というわけで、/usr/local/etc/apache24/extra/httpd-vhosts.conf の中の該当する部分を↓な感じで設定。
ついでに、http接続の旧サイトに来たアクセスをmod_rewriteでhttpsサイトにリダイレクトする設定を80番ポートのvirtualhostディレクティブに入れておくと、ブラウザが「この接続は危険です」とか言わなくなるのでおススメ。(何度も言うけど、個人的には何でもかんでもhttps化するのは好きじゃないんですけどね)
まあこんな感じかな。もちろん事前にhttpd.confで
とコメントアウトしとかなきゃダメですよ。
これでめでたしめでたし。
…じゃなかった。証明書の更新をcronに仕込んでおかないと。
/etc/crontabの編集
こちらの80番ポートが使用中だと更新に失敗するので、次のような感じでcrontabに一行追加しておきましたよ。
あとは適宜アクセスしてみたりログを確認したりしてチェックすること。
以上。