「Certbot」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(Kusanaginoturugi (トーク) による編集を Kusakata による直前の版へ差し戻しました)
(同じ利用者による、間の2版が非表示)
2行目: 2行目:
 
[[Category:セキュリティ]]
 
[[Category:セキュリティ]]
 
[[en:Let’s Encrypt]]
 
[[en:Let’s Encrypt]]
  +
[[ru:Let’s Encrypt]]
 
[https://letsencrypt.org/ Let’s Encrypt] はフリーかつ自動化されたオープンな認証局です。[[Wikipedia:ja:Automated Certificate Management Environment|ACME]] プロトコルを利用しています。
 
[https://letsencrypt.org/ Let’s Encrypt] はフリーかつ自動化されたオープンな認証局です。[[Wikipedia:ja:Automated Certificate Management Environment|ACME]] プロトコルを利用しています。
   
 
公式クライアントは '''Certbot''' という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを {{AUR|acme-tiny}} でインストールすることができます。スクリプトで使用するのに適したクライアントとして {{AUR|simp_le-git}} や {{AUR|letsencrypt-cli}} も存在します。
 
公式クライアントは '''Certbot''' という名前で、コマンドラインから有効な X.509 証明書を取得できます。また、手動で CSR 作成を行うミニマルなクライアントを {{AUR|acme-tiny}} でインストールすることができます。スクリプトで使用するのに適したクライアントとして {{AUR|simp_le-git}} や {{AUR|letsencrypt-cli}} も存在します。
   
  +
== インストール ==
{{Note|以前 ''Let’s Encrypt クライアント''と呼ばれていた公式クライアントは、現在 ''Certbot'' と呼ばれています。}}
 
 
== Certbot ==
 
 
''Certbot'' は公式のリファレンスクライアントです。Python で書かれており、証明書を取得するためのコマンドラインツールを提供します。
 
 
=== インストール ===
 
   
 
{{Pkg|certbot}} パッケージを[[インストール]]してください。
 
{{Pkg|certbot}} パッケージを[[インストール]]してください。
18行目: 13行目:
 
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:
 
公式クライアントを用いて発行された証明書はプラグインを使ってウェブサーバーに自動的に設定・インストールできます:
 
* [[Nginx]] 用の実験的なプラグインは {{Pkg|certbot-nginx}} パッケージに入っています。
 
* [[Nginx]] 用の実験的なプラグインは {{Pkg|certbot-nginx}} パッケージに入っています。
* {{Pkg|certbot-apache}} パッケージも存在していますが、[[Apache HTTP Server]] を使っている場合の自動インストールは現在 Debian の派生ディストリビュションしかサポートされていせん
+
* [[Apache HTTP Server]] 利用時の自動インストールは {{Pkg|certbot-apache}} パッケ使え
   
=== 設定 ===
+
== 設定 ==
   
 
証明を作成・インストールする方法は [https://certbot.eff.org/docs/ Certbot のドキュメント] を参照してください。
 
証明を作成・インストールする方法は [https://certbot.eff.org/docs/ Certbot のドキュメント] を参照してください。
   
==== 手動 ====
+
=== Webroot ===
  +
  +
{{Note|
  +
* Webroot 方式では Certbot で認証するのにポート 80 で HTTP 接続する必要があります。
  +
** ポート 443 で HTTPS 接続を使って Certbot で認証するには、Webroot (''--webroot'') 方式の代わりに Nginx (''--nginx'') または Apache (''--apache'') プラグインを使用する必要があります。
  +
* サーバー名は DNS 名と一致していなければなりません。
  +
* ホスト上のパーミッションを修正して {{ic|<nowiki>http://domain.tld/.well-known</nowiki>}} への読み取り許可を与える必要があります。
  +
}}
  +
  +
Webroot 方式では、Certbot クライアントによって {{ic|/path/to/domain.tld/html/.well-known/acme-challenge/}} でチャレンジ/レスポンス認証が行われます。
  +
  +
この使用方法は手動インストールよりも推奨されます。自動的に更新が行なわれ、証明書管理が容易になります。
  +
  +
{{Tip|1=始めて証明書を取得するときは以下の [[Nginx#サーバーブロック|nginx サーバー]]設定が役に立つでしょう:
  +
{{hc|/etc/nginx/servers-available/domain.tld|<nowiki>
  +
server {
  +
listen 80;
  +
listen [::]:80;
  +
server_name domain.tld;
  +
root /usr/share/nginx/html;
  +
location / {
  +
index index.htm index.html;
  +
}
  +
  +
# ACME challenge
  +
location ^~ /.well-known/acme-challenge/ {
  +
default_type "text/plain";
  +
root /var/lib/letsencrypt;
  +
}
  +
}</nowiki>}}
  +
}}
  +
  +
==== 証明書の取得 ====
  +
  +
公開パスとして {{ic|/var/lib/letsencrypt/}} を使って {{ic|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
  +
  +
証明書の更新方法については[[#自動更新]]も参照。
  +
  +
=== 手動 ===
   
 
{{Note|
 
{{Note|
42行目: 82行目:
 
{{Note|コマンドを複数回実行すると {{ic|/etc/letsencrypt/live/''your.domain''/}} に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。}}
 
{{Note|コマンドを複数回実行すると {{ic|/etc/letsencrypt/live/''your.domain''/}} に作られるファイルの名前には末尾に数字が付加されます。作成されたファイル名かウェブサーバーの設定を書き換える必要があります。}}
   
==== Webroot ====
+
== 高度な設定 ==
 
webroot の方法では、{{ic|yourdomain.tld/.well-known/acme-challenge/}} でチャレンジ/レスポンス認証が行われます。ウェブサーバーを止めることなく証明書を取得・更新できます:
 
   
  +
=== ウェブサーバーの設定 ===
# certbot certonly --email ''email@example.com'' --webroot -w ''/path/to/html/'' -d ''your.domain''
 
   
  +
プラグインを使用して自動で設定するのではなく、サーバーの SSL を手動で有効にすることが推奨される場合があります。
サーバーの設定で {{ic|/etc/letsencrypt/live/''your.domain''/}} の証明書を使うようにしてください。
 
   
  +
{{Tip|
{{Note|Apache または nginx の場合、{{ic|--webbroot}} ではなく {{ic|--apache}} または {{ic|--nginx}} をそれぞれ使用します。ポート443の代わりにポート80を使用して検証する必要がある場合は {{ic|--webroot}} を使用してください。}}
 
  +
* Mozilla には有用な [https://wiki.mozilla.org/Security/Server_Side_TLS SSL/TLS についての記事] があり、セキュアな設定を作成するための [https://mozilla.github.io/server-side-tls/ssl-config-generator/ 自動ツール] もあります。
  +
* [https://cipherli.st Cipherli.st] には最新のウェブサーバーのため強固な SSL の設定例とチュートリアルが載っています。
  +
}}
   
===== マルチドメイン =====
+
==== nginx ====
  +
Let's Encrypt の署名済み SSL 証明書を使用するサーバー {{ic|domain.tld}} の例:
   
  +
{{hc|/etc/nginx/servers-available/domain.tld|<nowiki>
複数のドメインあるいはサブドメインを使用する場合、全てのドメインに対して webroot を指定する必要があります。別の webroot を指定しないと、既存の webroot が使われます。
 
  +
# redirect to https
  +
server {
  +
listen 80;
  +
listen [::]:80;
  +
server_name domain.tld;
  +
return 301 https://$host$request_uri;
  +
}
   
  +
server {
{{ic|/.well-known/acme-challenge/}} への http リクエストを全て一つのフォルダ (例: {{ic|/var/lib/letsencrypt}}) にまとめることで、マルチドメインの管理がとても楽になります。nginx ならば、以下のようなファイルを作成:
 
  +
listen 443 ssl http2;
{{hc|/etc/nginx/letsencrypt.conf|<nowiki>
 
  +
listen [::]:443 ssl http2;
location ^~ /.well-known/acme-challenge {
 
alias /var/lib/letsencrypt/.well-known/acme-challenge;
+
ssl_certificate /etc/letsencrypt/live/domain.tld/fullchain.pem;
  +
ssl_certificate_key /etc/letsencrypt/live/domain.tld/privkey.pem;
default_type "text/plain";
 
  +
ssl_trusted_certificate /etc/letsencrypt/live/domain.tld/chain.pem;
try_files $uri =404;
 
  +
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;
  +
..
 
}
 
}
  +
</nowiki>}}
 
  +
# A subdomain uses the same SSL-certifcate:
そして証明書を作成したいサイトの server ブロックの中に以下のように記述します:
 
{{hc|/etc/nginx/servers/example.com.conf|<nowiki>
 
 
server {
 
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
include letsencrypt.conf;
 
  +
location ^~ /.well-known {
  +
allow all;
  +
alias /var/lib/letsencrypt/.well-known/;
  +
default_type "text/plain";
  +
try_files $uri =404;
 
}
 
}
 
</nowiki>}}
 
</nowiki>}}
   
  +
=== マルチドメイン ===
Apache の場合、{{ic|httpd-acme.conf}} ファイルを作成してください:
 
  +
  +
{{ic|/.well-known/acme-challenge/}} への HTTP リクエストを全て一つのフォルダ (例: {{ic|/var/lib/letsencrypt}}) にまとめることで、マルチドメインの管理がとても楽になります。
  +
  +
Let's Encrypt クライアントのパスから設定したパスに書き込めるように、また、ウェブサーバーから読み込めるようにする必要があります ([[nginx]] や [[Apache]] の場合 ''http'' ユーザー):
  +
# mkdir -p /var/lib/letsencrypt/.well-known
  +
# chgrp http /var/lib/letsencrypt
  +
# chmod g+s /var/lib/letsencrypt
  +
  +
==== nginx ====
  +
  +
まず location ブロックを記述したファイルを作成します:
  +
  +
{{hc|/etc/nginx/conf.d/letsencrypt.conf|<nowiki>
  +
location ^~ /.well-known {
  +
allow all;
  +
alias /var/lib/letsencrypt/.well-known/;
  +
default_type "text/plain";
  +
try_files $uri =404;
  +
}
  +
</nowiki>}}
  +
  +
そして server ブロックの中で作成したファイルを指定します:
  +
{{hc|/etc/nginx/servers-available/domain.conf|<nowiki>
  +
server {
  +
server_name domain.tld
  +
..
  +
include conf.d/letsencrypt.conf;
  +
}
  +
</nowiki>}}
  +
  +
==== Apache ====
  +
  +
{{ic|/etc/httpd/conf/extra/httpd-acme.conf}} ファイルを作成してください:
  +
 
{{hc|/etc/httpd/conf/extra/httpd-acme.conf|<nowiki>
 
{{hc|/etc/httpd/conf/extra/httpd-acme.conf|<nowiki>
 
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
 
Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/"
82行目: 186行目:
 
</Directory>
 
</Directory>
 
</nowiki>}}
 
</nowiki>}}
  +
そして {{ic|httpd.conf}} で上記ファイルをインクルードします:
 
  +
そして、{{ic|httpd.conf}} で上記ファイルをインクルードします:
  +
 
{{hc|/etc/httpd/conf/httpd.conf|<nowiki>
 
{{hc|/etc/httpd/conf/httpd.conf|<nowiki>
 
Include conf/extra/httpd-acme.conf
 
Include conf/extra/httpd-acme.conf
 
</nowiki>}}
 
</nowiki>}}
letsencrypt クライアントのパスから設定したパスに書き込めるように、また、ウェブサーバーから読み込めるようにする必要があります。次のコマンドを実行してください: {{ic|# chgrp http /var/lib/letsencrypt && chmod g+s /var/lib/letsencrypt}}。
 
   
===== 自動更新 =====
+
=== 自動更新 ===
   
  +
==== systemd ====
{{ic|certbot certonly}} を実行するとき、Certbot はドメインと webroot ディレクトリを {{ic|/etc/letsencrypt/renewal}} に記録します。次回からは {{ic|certbot renew}} を実行することで証明書を自動更新することができます。
 
  +
{{ic|certbot.service}} ユニットを作成:
 
====== サービス ======
 
以下の {{ic|.service}} ファイルを作成することで完全に自動化することが可能です:
 
   
 
{{hc|1=/etc/systemd/system/certbot.service|
 
{{hc|1=/etc/systemd/system/certbot.service|
103行目: 206行目:
 
ExecStart=/usr/bin/certbot renew --quiet --agree-tos}}
 
ExecStart=/usr/bin/certbot renew --quiet --agree-tos}}
   
  +
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。{{ic|certbot.service}} ファイルに以下のどちらかの行を追加してください:
====== Standalone サービス ======
 
Standalone プラグインを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。
 
   
  +
* Apache: {{ic|1=ExecStartPost=/bin/systemctl reload httpd.service}}
'''Nginx'''
 
{{hc|1=/etc/systemd/system/certbot.service|
+
* nginx: {{ic|1=ExecStartPost=/bin/systemctl reload nginx.service}}
2=[Unit]
 
Description=Let's Encrypt renewal
 
   
  +
{{Note|[[systemd/タイマー|タイマー]]を追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。}}
[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'''
 
{{hc|1=/etc/systemd/system/certbot.service|
 
2=[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}}
 
 
====== 自動更新タイマー ======
 
 
[[systemd/タイマー|タイマー]]を追加する前に、サービスが正しく動作すること、何も入力が要求されないことを確認してください。
 
   
 
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。
 
それから、タイマーを追加することで証明書を更新できます (更新の必要がない証明書は自動的にスキップされます)。
135行目: 220行目:
   
 
[Timer]
 
[Timer]
OnCalendar=daily
+
OnCalendar=0/12:00:00
RandomizedDelaySec=1day
+
RandomizedDelaySec=1h
 
Persistent=true
 
Persistent=true
   
144行目: 229行目:
 
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。
 
{{ic|certbot.timer}} を[[起動]]・[[有効化]]してください。
   
  +
==== Standalone を使う場合のサービス ====
証明書を更新するたびにウェブサーバーを再起動させると良いでしょう。{{ic|certbot.service}} ファイルに以下のどちらかの行を追加してください:
 
   
  +
Standalone モードを使用する場合は更新リクエストを実行する前にウェブサーバーを停止させて、更新が完了してからウェブサーバーを再起動するようにします。Certbot のフックを使ってください。
* Apache: {{ic|1=ExecStartPost=/bin/systemctl reload httpd.service}}
 
  +
* nginx: {{ic|1=ExecStartPost=/bin/systemctl reload nginx.service}}
 
  +
===== 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 =====
  +
  +
{{hc|1=/etc/systemd/system/certbot.service|
  +
2=[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}}
   
 
== 参照 ==
 
== 参照 ==
   
  +
* [https://certbot.eff.org/ EFF の Certbot ドキュメント]
 
* [https://letsencrypt.org/docs/client-options/ ACME クライアントの一覧]
 
* [https://letsencrypt.org/docs/client-options/ ACME クライアントの一覧]

2017年10月16日 (月) 00:27時点における版

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

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

インストール

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

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

設定

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

Webroot

ノート:
  • Webroot 方式では Certbot で認証するのにポート 80 で HTTP 接続する必要があります。
    • ポート 443 で HTTPS 接続を使って Certbot で認証するには、Webroot (--webroot) 方式の代わりに Nginx (--nginx) または Apache (--apache) プラグインを使用する必要があります。
  • サーバー名は DNS 名と一致していなければなりません。
  • ホスト上のパーミッションを修正して http://domain.tld/.well-known への読み取り許可を与える必要があります。

Webroot 方式では、Certbot クライアントによって /path/to/domain.tld/html/.well-known/acme-challenge/ でチャレンジ/レスポンス認証が行われます。

この使用方法は手動インストールよりも推奨されます。自動的に更新が行なわれ、証明書管理が容易になります。

ヒント: 始めて証明書を取得するときは以下の nginx サーバー設定が役に立つでしょう:
/etc/nginx/servers-available/domain.tld
server {
  listen 80;
  listen [::]:80;
  server_name domain.tld;
  root /usr/share/nginx/html;
  location / {
    index index.htm index.html;
  }

  # ACME challenge
  location ^~ /.well-known/acme-challenge/ {
    default_type "text/plain";
    root /var/lib/letsencrypt;
  }
}

証明書の取得

公開パスとして /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

証明書の更新方法については#自動更新も参照。

手動

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

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

# certbot certonly --manual

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

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

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

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

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

高度な設定

ウェブサーバーの設定

プラグインを使用して自動で設定するのではなく、サーバーの SSL を手動で有効にすることが推奨される場合があります。

ヒント:
  • Mozilla には有用な SSL/TLS についての記事 があり、セキュアな設定を作成するための 自動ツール もあります。
  • Cipherli.st には最新のウェブサーバーのため強固な 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;
}

マルチドメイン

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

Let's Encrypt クライアントのパスから設定したパスに書き込めるように、また、ウェブサーバーから読み込めるようにする必要があります (nginxApache の場合 http ユーザー):

# mkdir -p /var/lib/letsencrypt/.well-known
# chgrp http /var/lib/letsencrypt
# chmod g+s /var/lib/letsencrypt

nginx

まず location ブロックを記述したファイルを作成します:

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

そして server ブロックの中で作成したファイルを指定します:

/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

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

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

Standalone を使う場合のサービス

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

nginx
/etc/systemd/system/certbot.service
[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

参照