「Certbot」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
180行目: 180行目:
   
 
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。
 
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。
 
[[Enable]] and [[start]] {{ic|certbot.timer}}.
 
   
 
==== その他のサービス ====
 
==== その他のサービス ====

2017年10月13日 (金) 14:22時点における版

Let’s Encrypt はフリーかつ自動化されたオープンな認証局です。ACME プロトコルを利用しています。

公式クライアントは Certbot という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを acme-tinyAUR でインストールすることができます。スクリプトで使用するのに適したクライアントとして simp_le-gitAURletsencrypt-cliAUR も存在します。

ノート: 以前 Let’s Encrypt クライアントと呼ばれていた公式クライアントは、現在 Certbot と呼ばれています。

インストール

certbot パッケージをインストールしてください。

公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:

  • Nginx 用の実験的なプラグインは certbot-nginx パッケージに入っています。
  • certbot-apache パッケージも存在していますが、Apache HTTP Server を使っている場合の自動インストールは現在 Debian の派生ディストリビューションでしかサポートされていません。

設定

証明を作成・インストールする方法は Certbot のドキュメント を参照してください。

Webroot

webroot の方法では、yourdomain.tld/.well-known/acme-challenge/ でチャレンジ/レスポンス認証が行われます。ウェブサーバーを止めることなく証明書を取得・更新できます:

# certbot certonly --email email@example.com --webroot -w /path/to/html/ -d your.domain

サーバーの設定で /etc/letsencrypt/live/your.domain/ の証明書を使うようにしてください。

ノート: Apache または nginx の場合、--webroot ではなく --apache または --nginx をそれぞれ使用します。ポート443の代わりにポート80を使用して検証する必要がある場合は --webroot を使用してください。

手動

ノート:
  • この方法では、一時的にウェブサーバーを停止する必要があります。#Webroot の方法ではウェブサーバーを実行しながらでも認証が行えます。
  • この方法では、自動的に証明書を更新することはできません。自動更新を行いたい場合には、#Webroot メソッドを使用してください。

ウェブサーバーのプラグインが存在しない場合、次のコマンドを使って下さい:

# certbot certonly --manual

DNS の TXT レコードを利用した認証を行う場合、次のコマンドを使って下さい:

# certbot certonly --manual --preferred-challenges dns

上記のコマンドで自動的にドメインが認証されて秘密鍵と証明書のペアが作成されます。秘密鍵と証明書は /etc/letsencrypt/live/your.domain/ に保存されます。

上記のディレクトリに入っている秘密鍵と証明書を使用するように手動でウェブサーバーを設定します。

ノート: コマンドを複数回実行すると /etc/letsencrypt/live/your.domain/ に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。

高度な設定

Webserver Configuration

Instead of using plugins for automatic configuration, it may be preferred to enable SSL for a server manually.

ヒント:
  • Mozilla has a useful SSL/TLS article which includes an automated tool to help create a more secure configuration.
  • Cipherli.st provides strong SSL implementation examples and tutorial for most modern webservers.

nginx

An example of the server domain.tld using the signed SSL-certificate of Let's Encrypt:

/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;
}

マルチドメイン

複数のドメインあるいはサブドメインを使用する場合、全てのドメインに対して webroot を指定する必要があります。別の webroot を指定しないと、既存の webroot が使われます。

/.well-known/acme-challenge/ への http リクエストを全て一つのフォルダ (例: /var/lib/letsencrypt) にまとめることで、マルチドメインの管理がとても楽になります。nginx ならば、以下のようなファイルを作成:

/etc/nginx/letsencrypt.conf
location ^~ /.well-known/acme-challenge {
    alias /var/lib/letsencrypt/.well-known/acme-challenge;
    default_type "text/plain";
    try_files $uri =404;
}

そして証明書を作成したいサイトの server ブロックの中に以下のように記述します:

/etc/nginx/servers/example.com.conf
server {
    ...

    include letsencrypt.conf;
}

Apache の場合、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

letsencrypt クライアントのパスから設定したパスに書き込めるように、また、ウェブサーバーから読み込めるようにする必要があります。次のコマンドを実行してください: # chgrp http /var/lib/letsencrypt && chmod g+s /var/lib/letsencrypt

自動更新

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=daily
RandomizedDelaySec=1day
Persistent=true

[Install]
WantedBy=timers.target

certbot.timer起動有効化してください。

その他のサービス

Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。

nginx
/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 nginx.service" --post-hook "/usr/bin/systemctl start nginx.service" --quiet --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

参照