Certbot Webroot 設定手順書


対象OS Ubuntu 20.04/22.04、Debian 11/12、RHEL 8/9、AlmaLinux 8/9、Rocky Linux 8/9
Webサーバ Apache / Nginx
ACMEクライアント Certbot(webrootプラグイン)
証明書発行元 SSLセキュアが取り扱う外部認証局 ※現在、PositiveSSLが対応

🟠 Debian/Ubuntu Ubuntu 20.04/22.04、Debian 11/12
🔴 RedHat系 RHEL 8/9、AlmaLinux 8/9、Rocky Linux 8/9
共通 両系統で同じコマンド

1概要

1.1 本手順書の目的

SSLセキュアでご購入いただいたSSLサーバ証明書を、ACMEプロトコルを使って自動取得・自動更新するための設定手順を解説します。Certbot の webroot プラグインを使用し、既存のWebサーバを停止することなく証明書を取得・更新できます。

利用できるのは、ACME自動更新の契約が可能な証明書に限られます。2026年4月現在、PositiveSSL が対応しています。

1.2 webrootモードの仕組み

ACMEサーバからのチャレンジファイルを既存Webサーバのドキュメントルート配下に配置し、ドメインの所有権を証明します。

① Certbot

チャレンジファイルを
/.well-known/acme-challenge/ に配置

② ACMEサーバ

HTTP経由でチャレンジファイルにアクセスし、ドメイン所有権を検証

③ 証明書発行

検証成功により証明書を発行。Webサーバの停止は不要

Webサーバは停止不要。80番ポートで通常通りサービスを継続しながら認証できます。

1.3 事前準備・前提条件

項目 内容
ドメイン 証明書を取得するFQDN(例:example.com)が確定していること
DNSレコード 対象ドメインのAレコードが本サーバのグローバルIPを向いていること
80番ポート 外部からHTTPアクセス(TCP/80)が到達できること
Webサーバ動作 Apache または Nginx が稼働し、webrootディレクトリが公開済みであること
認証局情報 ACME Server URL / Key ID / HMAC Key がSSLセキュアの管理画面から取得済みであること
sudo権限 作業ユーザが sudo 実行できること

2設定手順

STEP 1
Certbot のインストール

# snapd のインストール(未導入の場合)
sudo apt update && sudo apt install -y snapd

# 既存 certbot パッケージの削除(競合防止)
sudo apt remove certbot

# snap 経由で certbot をインストール
sudo snap install --classic certbot

# certbot コマンドをパスに通す
sudo ln -s /snap/bin/certbot /usr/bin/certbot

# バージョン確認
certbot --version

# EPEL リポジトリの有効化
sudo dnf install -y epel-release

# RHEL 8/9 のみ:CodeReady Builder を有効化(AlmaLinux/Rocky Linux は不要)
# RHEL 9 の場合
sudo subscription-manager repos --enable codeready-builder-for-rhel-9-x86_64-rpms
# RHEL 8 の場合
# sudo subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms

# 既存 certbot パッケージの削除(競合防止)
sudo dnf remove certbot

# snapd のインストール
sudo dnf install -y snapd
sudo systemctl enable --now snapd.socket

# snapd のシンボリックリンク作成
sudo ln -s /var/lib/snapd/snap /snap

# 一度ログアウトして再ログイン後、certbot をインストール
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

# バージョン確認
certbot --version

snapd が利用できない環境では sudo pip3 install certbot でも導入可能ですが、snap版が最新バージョンを保ちやすいため推奨します。

STEP 2
EAB(外部アカウントバインディング)情報の確認

SSLセキュアの管理画面から以下の3つの情報を取得してください。

パラメータ 説明
ACME Server URL 認証局のACMEエンドポイントURL https://acme.example-ca.com/acme/directory
Key ID EAB用のキーID(アカウント識別子) abc123def456...
HMAC Key EAB用のHMAC秘密鍵(Base64URL形式) XyZ9a1B2c3D4...(長い文字列)
HMAC Key は秘密情報です。ファイルに保存する場合は root のみ読み取り可能な権限(chmod 600)を設定してください。

STEP 3
ファイアウォールの確認

80番・443番ポートが外部から到達できることを確認します。


# 状態確認
sudo ufw status

# HTTP / HTTPS を許可
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# 状態確認
sudo firewall-cmd --list-all

# HTTP / HTTPS を永続的に許可
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

STEP 4
webroot ディレクトリの設定

ACMEチャレンジ用のパス(/.well-known/acme-challenge/)がHTTPで公開される必要があります。

Apache の場合

# バーチャルホスト設定ファイルを確認
sudo cat /etc/apache2/sites-enabled/000-default.conf
# DocumentRoot の値を控えておく(例: /var/www/html)

# 設定ファイルを確認(ファイル名は環境に合わせて読み替え)
sudo cat /etc/httpd/conf.d/vhost.conf
# DocumentRoot の値を控えておく(例: /var/www/html)

Nginx の場合

# /etc/nginx/sites-available/your-domain の server ブロックに追記
location /.well-known/acme-challenge/ {
    root /var/www/html;
}

sudo nginx -t && sudo systemctl reload nginx

# /etc/nginx/conf.d/your-domain.conf の server ブロックに追記
location /.well-known/acme-challenge/ {
    root /var/www/html;
}

sudo nginx -t && sudo systemctl reload nginx

チャレンジディレクトリの作成と動作確認 共通
# ディレクトリを作成
sudo mkdir -p /var/www/html/.well-known/acme-challenge

# 動作確認用テストファイルを配置
echo "ok" | sudo tee /var/www/html/.well-known/acme-challenge/test.txt

# 外部からアクセス確認("ok" と表示されれば問題なし)
curl http://your-domain.example.com/.well-known/acme-challenge/test.txt

# テストファイルを削除
sudo rm /var/www/html/.well-known/acme-challenge/test.txt
🔴 RedHat系:SELinux の注意
SELinux が有効な場合、Webサーバが .well-known にアクセスできず 403 エラーになることがあります。その場合は以下を実行してください。
sudo restorecon -Rv /var/www/html/.well-known/

STEP 5
Certbot アカウント登録(EAB付き)

SSLセキュアの認証局ACMEサーバに対して、EAB情報を使用してアカウントを登録します。

sudo certbot register \
  --server https://acme.example-ca.com/acme/directory \
  --email admin@your-domain.example.com \
  --eab-kid  "<管理画面の Key ID>" \
  --eab-hmac-key "<管理画面の HMAC Key>" \
  --agree-tos \
  --no-eff-email
--server にはSSLセキュアの管理画面に表示されているACMEディレクトリURLを指定します。--eab-kid / --eab-hmac-key は管理画面の値をそのままコピーしてください。

STEP 6
証明書の取得(初回)
sudo certbot certonly \
  --webroot \
  --webroot-path /var/www/html \
  --server https://acme.example-ca.com/acme/directory \
  -d your-domain.example.com \
  -d www.your-domain.example.com \
  --email admin@your-domain.example.com \
  --agree-tos \
  --no-eff-email
取得成功時の出力例
Successfully received certificate.
Certificate is saved at:
  /etc/letsencrypt/live/your-domain.example.com/fullchain.pem
Key is saved at:
  /etc/letsencrypt/live/your-domain.example.com/privkey.pem
取得される証明書ファイル
fullchain.pem
/etc/letsencrypt/live/<domain>/
サーバ証明書+中間CA証明書
privkey.pem
/etc/letsencrypt/live/<domain>/
秘密鍵
cert.pem
/etc/letsencrypt/live/<domain>/
サーバ証明書のみ
chain.pem
/etc/letsencrypt/live/<domain>/
中間CA証明書のみ

STEP 7
Webサーバへの証明書設定
Apache の場合

# /etc/apache2/sites-available/your-domain-ssl.conf を作成
<VirtualHost *:443>
    ServerName your-domain.example.com
    DocumentRoot /var/www/html
    SSLEngine on
    SSLCertificateFile    /etc/letsencrypt/live/your-domain.example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/your-domain.example.com/chain.pem
</VirtualHost>

sudo a2enmod ssl
sudo a2ensite your-domain-ssl.conf
sudo systemctl reload apache2

# mod_ssl のインストール(未導入の場合)
sudo dnf install -y mod_ssl

# /etc/httpd/conf.d/your-domain-ssl.conf を作成
<VirtualHost *:443>
    ServerName your-domain.example.com
    DocumentRoot /var/www/html
    SSLEngine on
    SSLCertificateFile    /etc/letsencrypt/live/your-domain.example.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/your-domain.example.com/chain.pem
</VirtualHost>

# 設定反映(a2ensite は不要)
sudo systemctl reload httpd

Nginx の場合

# /etc/nginx/sites-available/your-domain を編集
server {
    listen 443 ssl;
    server_name your-domain.example.com;
    ssl_certificate     /etc/letsencrypt/live/your-domain.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.example.com/privkey.pem;
}

sudo ln -s /etc/nginx/sites-available/your-domain /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

# /etc/nginx/conf.d/your-domain-ssl.conf を作成
server {
    listen 443 ssl;
    server_name your-domain.example.com;
    ssl_certificate     /etc/letsencrypt/live/your-domain.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.example.com/privkey.pem;
}

# conf.d は自動読み込みのためシンボリックリンク不要
sudo nginx -t && sudo systemctl reload nginx

STEP 8
自動更新の設定
自動更新タイマーの確認 共通
# timer の状態確認
sudo systemctl status certbot.timer

# 手動で更新テスト(dry-run)
sudo certbot renew --dry-run \
  --server https://acme.example-ca.com/acme/directory
更新後の Webサーバ再起動フック設定


sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-apache.sh << 'EOF'
#!/bin/sh
systemctl reload apache2
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-apache.sh

sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-httpd.sh << 'EOF'
#!/bin/sh
systemctl reload httpd
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-httpd.sh

sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh << 'EOF'
#!/bin/sh
systemctl reload nginx
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

renewal 設定ファイルの確認 共通
sudo cat /etc/letsencrypt/renewal/your-domain.example.com.conf

server が認証局のURLになっていることを確認します:

[renewalparams]
authenticator = webroot
server = https://acme.example-ca.com/acme/directory
webroot_path = /var/www/html

3動作確認

# 取得済み証明書の一覧確認
sudo certbot certificates

# OpenSSL での証明書内容確認
openssl x509 -in /etc/letsencrypt/live/your-domain.example.com/cert.pem \
  -noout -text | grep -E "Subject:|Issuer:|Not After"

# HTTPS 接続確認
curl -v https://your-domain.example.com 2>&1 | grep -E "SSL|subject|expire"

# 次回更新予定の確認
sudo systemctl list-timers certbot.timer

4トラブルシューティング

エラー内容 原因 対処法
Connection refused (port 80) ファイアウォールが80番をブロック 🟠 ufw allow 80/tcp / 🔴 firewall-cmd --add-service=http
Challenge failed: 404 webroot-path の設定ミス DocumentRoot と --webroot-path が一致するか確認
Challenge failed: 403 SELinux によるアクセス拒否(🔴 RedHat系) restorecon -Rv /var/www/html/.well-known/ を実行
EAB credentials error Key ID / HMAC Key が誤り SSLセキュア管理画面で再発行して再登録
Server URL not found ACMEサーバURLの誤り 管理画面のURLを再確認
Permission denied webroot への書き込み権限不足 sudo を付けて実行、またはディレクトリ権限を確認
renewal conf に server が反映されない 初回取得時に –server を省略 conf ファイルに手動で server = を追記
snap: command not found(🔴 RedHat系) snapd のパスが未設定 sudo ln -s /var/lib/snapd/snap /snap を実行後、再ログイン
詳細なエラーは /var/log/letsencrypt/letsencrypt.log を参照してください。--verbose オプションを追加すると詳細な出力が得られます。

5ディストリビューション別 主要パス・コマンド早見表

項目 🟠 Debian / Ubuntu 🔴 RedHat系
パッケージ管理 apt dnf
Apache サービス名 apache2 httpd
Apache 設定ディレクトリ /etc/apache2/sites-available/ /etc/httpd/conf.d/
Apache サイト有効化 a2ensite / a2enmod 不要(conf.d に配置するだけ)
Apache SSL モジュール sudo a2enmod ssl sudo dnf install mod_ssl
Nginx 設定ディレクトリ /etc/nginx/sites-available/ /etc/nginx/conf.d/
Nginx サイト有効化 sites-enabled へのシンボリックリンク 不要(conf.d に配置するだけ)
ファイアウォール ufw firewalld
SELinux 通常無効 有効(要確認)
snapd シンボリックリンク 自動 /var/lib/snapd/snap → /snap の作成が必要

ページ上部へ戻る