Let's encryptの設定
参考サイト
Let's encrypt とは?
「安全な接続を世界中に広めよう」という素晴らしい考えを持ったプロジェクト。
非営利団体の ISRG (Internet Security Research Group) によって運営されており、いろいろな大手企業がこの活動をサポートしている。利用料はもちろん無料。
なにがすごいんじゃ
Let's encrypt では、「certbot」というクライアントソフトを使うことで、
自動的にSSL証明書の更新を行うことが出来るようになっている。
独自ドメインさえあればコマンド操作のみでSSL証明書がゲット出来るのである。
Amazon Linux に入れてみよう
Amazon Linuxはcertbotにまだ対応できていないため、単純にyumインストールができない(2017/11/16現在)
その為wgetでソースを落として直接インストールする必要がある。
$ wget https://dl.eff.org/certbot-auto
--2017-11-16 12:49:31-- https://dl.eff.org/certbot-auto
dl.eff.org (dl.eff.org) をDNSに問いあわせています... 151.101.32.201, 2a04:4e42:8::201
dl.eff.org (dl.eff.org)|151.101.32.201|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 57312 (56K) [application/octet-stream]
`certbot-auto' に保存中
certbot-auto 100%[==============================>] 55.97K --.-KB/s in 0.02s
2017-11-16 12:49:31 (2.39 MB/s) - `certbot-auto' へ保存完了 [57312/57312]
$ chmod a+x certbot-auto
ここまでは公式サイトに乗っている手順通り。
後1コマンド!・・・というところでこんな表示が出てしまう。
$ ./certbot-auto
Requesting to rerun ./certbot-auto with root privileges...
FATAL: Amazon Linux support is very experimental at present...
if you would like to work on improving it, please ensure you have backups
and then run this script again with the --debug flag!
Alternatively, you can install OS dependencies yourself and run this script
again with --no-bootstrap.
要約すると、
「Amazon Linuxでのcertbotはまだ実験段階だよ。もし君がその実験のお手伝いをしたいならバックアップを必ず取ってさっきのコマンドに--debugオプションを付けて実行してね!」
と書いてある。優しい。
というわけでバックアップをとって自己責任で実行してみる。
$ ./certbot-auto --debug
Requesting to rerun ./certbot-auto with root privileges...
Bootstrapping dependencies for Amazon... (you can skip this with --no-bootstrap)
yum は /usr/bin/yum です
読み込んだプラグイン:priorities, update-motd, upgrade-helper
パッケージ 1:openssl-1.0.2k-8.105.amzn1.x86_64 はインストール済みか最新バージョンです
パッケージ ca-certificates-2015.2.6-65.0.1.16.amzn1.noarch はインストール済みか最新バージョンです
パッケージ python27-2.7.12-2.121.amzn1.x86_64 はインストール済みか最新バージョンです
パッケージ python27-devel-2.7.12-2.121.amzn1.x86_64 はインストール済みか最新バージョンです
パッケージ python27-virtualenv-15.1.0-1.14.amzn1.noarch はインストール済みか最新バージョンです
パッケージ python27-pip-9.0.1-1.24.amzn1.noarch はインストール済みか最新バージョンです
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ augeas-libs.x86_64 0:1.0.0-5.7.amzn1 を インストール
~省略~
依存性を解決しました
===============================================================================================
Package アーキテクチャー
バージョン リポジトリー 容量
===============================================================================================
インストール中:
augeas-libs x86_64 1.0.0-5.7.amzn1 amzn-main 345 k
gcc noarch 4.8.5-1.22.amzn1 amzn-main 4.1 k
~省略~
トランザクションの要約
===============================================================================================
インストール 6 パッケージ (+17 個の依存関係のパッケージ)
総ダウンロード容量: 32 M
インストール容量: 61 M
Is this ok [y/d/N]:
お、なんとかなりそう。
というわけで実行しましょう。ちゃんと完了しました!と表示されるはずです。
これでインストールが完了です。ここからが本番です。
証明書を取得する
以下のコマンドを入力し、証明書を入手します。
./certbot-auto certonly --webroot -w [ドキュメントルート] -d [ドメイン]
--webrootオプションをつけることで、Webサーバを停止することなく実行できます。
以下のメッセージが表示されていれば成功です。
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/[ドメイン名]/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/[ドメイン名]/privkey.pem
Your cert will expire on 2018-02-14. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
皆さん寄付をご検討ください。
このメッセージが表示されていれば、以下のパスに証明書ファイルが生成されています。
見に行きましょう。
$ cd /etc/letsencrypt/live/[ドメイン名]/
$ ls
cert.pem chain.pem fullchain.pem privkey.pem README
こいつらが生成されていればOK
Apacheにmod_SSLをインストールするのをお忘れなく
$ yum install -y mod24_ssl
ssl.confを修正
$ vi /etc/httpd/conf.d/ssl.conf
以下を記述
SSLCertificateFile /etc/letsencrypt/live/[ドメイン名]/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/[ドメイン名]/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/[ドメイン名]/chain.pem
んでApaheを再起動すれば完了!
service httpd restart
問題なければここでおわり!
本当はhttpのアクセスをhttpsに流したりとかあるんだろうけど、それはまた別のお話。
お疲れ様でした。
...Apacheが起動しない人へ
最後に何故かApacheが起動しなくなりました・・エラーメッセージは以下
Starting httpd: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
443ポートがすでに使われているとのこと。しかしポートが使われている形跡はない・・・
悩みに調べて30分後
「もしやhttpd自身が443ポートを2回バインドしようとしているのでは・・・?」
とおもいhttpd.confを見てみると、ありました
Listen 443
こいつ。ssl.confの中にも書いてあるんですね。
httpd.confの方をコメントアウトしてhttpd再起動!
上手く行った!!!
よかったよかった。
誰かの助けになればいいなと思います。