LoginSignup
1
0

More than 5 years have passed since last update.

Lets Encrypt + certbot + nginx + CentOS7 + GCE

Last updated at Posted at 2018-06-19

TL;DL;

CentOS 7 + nginx の環境で Let's Encrypt を使うために certbot を動作させようとすると、バグのようなものを踏むので注意

環境

  • GCE: f1-micro, https-serverタグをつけて 443ポートが通るように設定済
  • CentOS 7 (7.5.1804)
  • nginx は yum で導入
  • ドメイン取得済み/DNS登録済み

大まかな手順

certbot のページに行って、プラットフォーム(nginx, centos7)を選ぶとやり方が出てくるのでその手順通りに進めればよい(要シェル、root権限)。Let's Encryptのページに行く必要すらない。以下その内容を記載

  • プラグイン導入: yum install python2-certbot-nginx
  • certbot起動 ★はまりどころ sudo certbot --nginx
  • 対話シェルで答えて終わり
  • 自動更新できるかチェック: sudo certbot renew --dry-run
  • cron で自動更新(0時前後と12時前後に renew)
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew

あれこれ疑問

nginx.conf 書き換えなくていいの?
certbot が勝手に書き換えてくれる。一通り手順が終わったら、/etc/nginx.conf の内容を見てみよう。

なんかつながらない
GCEやAWSでは、明示的にhttpsのポート443をあける必要がある。忘れてない?

はまりポイントって?
よくわかんない(というか調べようとすらしてない)けど、certbot が依存するpythonライブラリが、pipとディストリ(RPM)で多重管理されてうまく動かない、と解釈。このパターンが多すぎるのでCentOS/RHELはクソ。

https://github.com/certbot/certbot/issues/5104#issuecomment-355020248 で提示されたコマンドはこちら。certbotとは別に動作している自分のpythonプログラムが、OS標準の python を使ってると影響出るかもしれないので注意。

pip uninstall requests
pip uninstall urllib3
yum remove python-urllib3
yum remove python-requests
yum install python-urllib3
yum install python-requests
yum install certbot

Let's Encrypt と certbot の関係は?

Let's Encryptが証明書を発行してくれる機関のようなもの。certbot は Let's Encrypt を使うためのツールのようなイメージ。ACME protocol あたりがキーワードかな。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0