Certbot
Let’s Encrypt はフリーかつ自動化されたオープンな認証局です。ACME プロトコルを利用しています。
公式クライアントは Certbot という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを acme-tinyAUR でインストールすることができます。スクリプトで使用するのに適したクライアントとして simp_le-gitAUR や letsencrypt-cliAUR も存在します。
目次
インストール
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:
- Nginx 用の実験的なプラグインは certbot-nginx パッケージに入っています。
- Apache HTTP Server 利用時の自動インストールは、certbot-apache パッケージにより有効になっています。
設定
証明を作成・インストールする方法は Certbot のドキュメント を参照してください。
Webroot
webroot メソッドを使用する場合、certbotクライアントは検証のために使用される、/path/to/domain.tld/html/.well-known/acme-challenge/ の中でチャレンジ/レスポンス認証が行われます。
この使用方法は手動インストールよりも推奨されます。自動的に更新が行なわれ、証明書管理が容易になります。
証明書を取得する
/var/lib/letsencrypt/ を公開アクセス可能なパスとして使用して、domain.tld の証明書を要求します:
# certbot certonly --email email@example.com --webroot -w /var/lib/letsencrypt/ -d domain.tld
(サブ)ドメインを追加するには、現在のセットアップで使用されているすべての登録済みドメインを含めます:
# certbot certonly --email email@example.com --webroot -w /var/lib/letsencrypt/ -d domain.tld,sub.domain.tld
現在の証明書を(すべて)更新するには:
# certbot renew
変わりのアプローチとして #自動更新 を参照してください。
手動
ウェブサーバーのプラグインが存在しない場合、次のコマンドを使って下さい:
# certbot certonly --manual
DNS の TXT レコードを利用した認証を行う場合、次のコマンドを使って下さい:
# certbot certonly --manual --preferred-challenges dns
上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は /etc/letsencrypt/live/your.domain/ に保存されます。
上記のディレクトリに入っている秘密鍵と証明書を使用するように手動でウェブサーバーを設定します。
高度な設定
Webサーバーの設定
自動構成にプラグインを使用する代わりに、サーバーのSSLを手動で有効にすることをお勧めします。
nginx
Let's Encrypt の署名付きSSL証明書を使用したサーバー domain.tld の例:
/etc/nginx/servers-available/domain.tld
# redirect to https
server {
listen 80;
listen [::]:80;
server_name domain.tld;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name domain.tld;
..
}
# A subdomain uses the same SSL-certifcate:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
..
server_name sub.domain.tld;
..
}
# ACME challenge
location ^~ /.well-known {
allow all;
alias /var/lib/letsencrypt/.well-known/;
default_type "text/plain";
try_files $uri =404;
}
マルチドメイン
Management of can be made easier by mapping all HTTP-requests for /.well-known/acme-challenge/ to a single folder, e.g. /var/lib/letsencrypt.
The path has then to be writable for the Let's Encrypt client and the web server (e.g. nginx or Apache running as user http):
# mkdir -p /var/lib/letsencrypt/.well-known # chgrp http /var/lib/letsencrypt # chmod g+s /var/lib/letsencrypt
nginx
locationブロックを含むファイルを作成し、これを Serverブロック内に組み込みます:
/etc/nginx/conf.d/letsencrypt.conf
location ^~ /.well-known {
allow all;
alias /var/lib/letsencrypt/.well-known/;
default_type "text/plain";
try_files $uri =404;
}
サーバー構成の例:
/etc/nginx/servers-available/domain.conf
server {
server_name domain.tld
..
include conf.d/letsencrypt.conf;
}
Apache
/etc/httpd/conf/extra/httpd-acme.conf ファイルを作成してください:
/etc/httpd/conf/extra/httpd-acme.conf
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
<Directory "/var/lib/letsencrypt/">
AllowOverride None
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
そして、httpd.conf で上記ファイルをインクルードします:
/etc/httpd/conf/httpd.conf
Include conf/extra/httpd-acme.conf
自動更新
systemd
systemd certbot.service ファイルを作成します
/etc/systemd/system/certbot.service
[Unit] Description=Let's Encrypt renewal [Service] Type=oneshot ExecStart=/usr/bin/certbot renew --quiet --agree-tos
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。certbot.service ファイルに以下のどちらかの行を追加してください:
- Apache:
ExecStartPost=/bin/systemctl reload httpd.service - nginx:
ExecStartPost=/bin/systemctl reload nginx.service
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。
/etc/systemd/system/certbot.timer
[Unit] Description=Daily renewal of Let's Encrypt's certificates [Timer] OnCalendar=0/12:00:00 RandomizedDelaySec=1h Persistent=true [Install] WantedBy=timers.target
その他のサービス
Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。
nginx
{{hc|1=/etc/systemd/system/certbot.service| 2=[Unit] Description=Let's Encrypt renewal
[Service] Type=oneshot ExecStart=/usr/bin/certbot renew --post-hook "/usr/bin/systemctl restart nginx.service" --agree-tos
Apache
/etc/systemd/system/certbot.service
[Unit] Description=Let's Encrypt renewal [Service] Type=oneshot ExecStart=/usr/bin/certbot renew --pre-hook "/usr/bin/systemctl stop httpd.service" --post-hook "/usr/bin/systemctl start httpd.service" --quiet --agree-tos