質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Q&A

1回答

1178閲覧

Let's Encryptの自動更新がエラーになる(ubuntu/apache)

sumagimo

総合スコア16

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

0グッド

0クリップ

投稿2019/06/06 09:22

編集2019/06/07 06:36

証明書の設定までは上手く行きましたが自動更新がシミュレーション段階でエラーになってしまいます。

環境

ubuntu 18.04.2
apache 2.4.29

やりたいこと

aaa.example
www.aaa.example
www.bbb.example
上記3ドメインにLet's Encryptの自動更新のクーロンをセットしたい
※aaa.example、www.aaa.example、www.bbb.exampleともに最終的にはccc.exampleにリダイレクトさせる

実行した手順

  1. httpからhttpsへのリダイレクトを停止し、httpでレスポンスさせておく

  2. 証明書の取得

$ sudo certbot certonly --webroot -w /var/www/html/ -d aaa.example
$ sudo certbot certonly --webroot -w /var/www/html/ -d www.aaa.example
$ sudo certbot certonly --webroot -w /var/www/html/ -d www.bbb.example

※下記コマンドがエラーになったため取得と設定を別々に作業することにした
※$ sudo certbot --apache -d aaa.example -d www.aaa.example -d www.bbb.example

  1. 証明書の反映

$ sudo vi aaa.example-ssl.conf
$ sudo vi www.aaa.example-ssl.conf
$ sudo vi www.bbb.example-ssl.conf
それぞれのファイルの証明書の部分を変更
SSLCertificateFile /etc/letsencrypt/live/[サーバーのドメイン]/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/[サーバーのドメイン]/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/[サーバーのドメイン]/chain.pem

  1. httpからhttpsへのリダイレクトを有効にする

  2. それぞれのドメインのhttpsを有効にする

$ sudo a2ensite aaa.example-ssl.conf
$ sudo a2ensite www.aaa.example-ssl.conf
$ sudo a2ensite www.bbb.example-ssl.conf
・設定反映
$ sudo apachectl configtest
$ sudo /etc/init.d/apache2 reload

  1. httpからhttpsへリダイレクトしていることを確認

  2. 証明書が正しく反映されていることを確認

aaa.example-ssl.conf
www.aaa.example-ssl.conf
www.bbb.example-ssl.conf
ともに特定のURLはccc.exampleにリダイレクトしない除外設定を仕込んで確認

  1. 証明書自動更新のシミュレーション

$ sudo certbot renew --dry-run

  1. エラーが発生

dry runの実行結果

Saving debug log to /var/log/letsencrypt/letsencrypt.log


Processing /etc/letsencrypt/renewal/aaa.example.conf


Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for aaa.example
Waiting for verification...
Cleaning up challenges
Attempting to renew cert (aaa.example) from /etc/letsencrypt/renewal/aaa.example.conf produced an unexpected error: Failed authorization procedure. aaa.example (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://ccc.example/ [xxx.xxx.xx.xxx]: "[ccc.exampleのindex.htmlの応答]". Skipping.


Processing /etc/letsencrypt/renewal/www.bbb.example.conf


Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.bbb.example
Cleaning up challenges
Attempting to renew cert (www.bbb.example) from /etc/letsencrypt/renewal/www.bbb.example.conf produced an unexpected error: Missing command line flag or config entry for this setting:
Input the webroot for www.bbb.example:. Skipping.


Processing /etc/letsencrypt/renewal/www.aaa.example.conf


Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.aaa.example
Waiting for verification...
Cleaning up challenges
Attempting to renew cert (www.aaa.co.example) from /etc/letsencrypt/renewal/www.aaa.example.conf produced an unexpected error: Failed authorization procedure. www.aaa.example (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://ccc.example/ [xx.xxx.xxx.xxx]: "[ccc.exampleのindex.htmlの応答]". Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/aaa.example/fullchain.pem (failure)
/etc/letsencrypt/live/www.bbb.example/fullchain.pem (failure)
/etc/letsencrypt/live/www.aaa.example/fullchain.pem (failure)


** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates below have not been saved.)

All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/aaa.example/fullchain.pem (failure)
/etc/letsencrypt/live/www.bbb.example/fullchain.pem (failure)
/etc/letsencrypt/live/www.aaa.example/fullchain.pem (failure)
** DRY RUN: simulating 'certbot renew' close to cert expiry
** (The test certificates above have not been saved.)


3 renew failure(s), 0 parse failure(s)

IMPORTANT NOTES:

  • The following errors were reported by the server:

    Domain: aaa.example
    Type: unauthorized
    Detail: Invalid response from https://ccc.example/
    [xxx.xxx.xxx.xxx]: "[ccc.exampleのindex.htmlの応答]"

    To fix these errors, please make sure that your domain name was
    entered correctly and the DNS A/AAAA record(s) for that domain
    contain(s) the right IP address.

  • The following errors were reported by the server:

    Domain: www.aaa.example
    Type: unauthorized
    Detail: Invalid response from https://ccc.example/
    [xxx.xxx.xxx.xxx]: "[ccc.exampleのindex.htmlの応答]"

    To fix these errors, please make sure that your domain name was
    entered correctly and the DNS A/AAAA record(s) for that domain
    contain(s) the right IP address.

  • Your account credentials have been saved in your Certbot
    configuration directory at /etc/letsencrypt. You should make a
    secure backup of this folder now. This configuration directory will
    also contain certificates and private keys obtained by Certbot so
    making regular backups of this folder is ideal.

対策したこと

aaa.example.conf
www.aaa.example.conf
www.bbb.example.conf
上記に対してサーバの認証で使用する(と思われる)pathをドキュメントルートに作成し、リダイレクトから除外してhttpで反応するようにした
除外PATH /var/www/html/.well-known/acme-challenge/

→結果は変わらず

原因と思われること

証明書の取得でサーバ認証PATHに /var/www/html/ を指定したこと

リダイレクトの設定

aaa.example.conf
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
RewriteRule ^(.*)$ https://aaa.example$1 [R=301,L]

www.aaa.example.conf
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
RewriteRule ^(.*)$ https://www.aaa.example$1 [R=301,L]

www.bbb.example.conf
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/$
RewriteRule ^(.*)$ https://www.bbb.example$1 [R=301,L]

aaa.example-ssl.conf
RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外
RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]

www.aaa.example-ssl.conf
RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外
RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]

www.bbb.example-ssl.conf
RewriteCond %{REQUEST_URI} !^/check/$ ※証明書確認のための除外
RewriteRule ^(.*)$ https://ccc.example$1 [R=301,L]

apacheの設定

apache2.conf

DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/.load
IncludeOptional mods-enabled/
.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>

<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
LogFormat "%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/.conf
IncludeOptional sites-enabled/
.conf

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2019/06/06 10:43

それぞれのドメインの apache やリダイレクトの設定を記載していただけないでしょうか? また、ドメインは例示用ドメインを使用するようにしてください。
sumagimo

2019/06/07 00:57

修正依頼ありがとうございます。 修正、追記してみました。 よろしくお願いいたします。
guest

回答1

0

本来は、間違えたディレクトリを指定して発行した証明書を一度削除して、正しいディレクトリを指定して certbot によるSSL証明書を再度、新規発行することだと思います。

削除して作り直す以外の方法だと...

各ドメインの ^/.well-known$ をリダイレクトしないようにしておいて、次のどちらかの方法でしょうか。


(1) Apache で、 Alias を設定する。

certbot が、ドメインの存在確認ファイルを作成するディレクトリの /var/www/html/.well-known を Apache の バーチャルホスト設定の中で、Alias を設定して、 /.well-known に割り当てる。

Alias /.well-known /var/www/html/.well-known

(2)シンボリックリンク

certbot が、ドメインの存在確認ファイルを作成するディレクトリの /var/www/html/.well-known を各ドメインの DocumentRoot の中に .well-known という名前で、シンボリックリンクする

# cd aaa.exampleのDocumentRoot # ln -s /var/www/html/.well-known/ .well-known # cd aaa.exampleのDocumentRoot ln -s /var/www/html/.well-known/ .well-known # cd www.bbb.exampleのDocumentRoot # ln -s /var/www/html/.well-known/ .well-known

他にも

http 認証をやめて、DNS 認証にする

という方法もあります。

興味があれば Challenge Types を読んで試してみてください。

投稿2019/06/07 03:07

編集2019/06/07 03:08
CHERRY

総合スコア25171

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sumagimo

2019/06/07 06:21

回答ありがとうございます。 >本来は、間違えたディレクトリを指定して発行した証明書を一度削除して、正しいディレクトリを指定して certbot によるSSL証明書を再度、新規発行することだと思います。 はい、原因は証明書発行時のPATHにあるのではないかと思っていますので、最終手段としては試そうと思っています。 シンボリックリンクは検証してみます。 検証結果は追って報告いたします。 ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問