LoginSignup
25
20

More than 3 years have passed since last update.

letsencryptの更新がうまくできない場合

Last updated at Posted at 2018-01-08

新記事
https://qiita.com/ma7ma7pipipi/items/3d802e1125df98117fe5
https://qiita.com/ma7ma7pipipi/items/a700659ce1989d97a371

ラブレターの場合


/home/hideki/certbot/certbot-auto certonly --webroot -w /var/www/html/acme/ -d love-letter.club --agree-tos --force-re
newal -n

で、

service nginx restart

で更新できる。。。


ポートも開けてる?


firewall-cmd --add-service=https --zone=public --permanent
firewall-cmd --reload


どうしてもうまくいかん場合は一番したの強制更新で手動でやる。

流れは

・サーバー移転する際にhttpsを切らさずにやる。
・webrootモードにする (これをやらんと更新がうまくできなかったりする)
・自動更新をオンにするため、cron仕掛ける

cron 設定は

--force-renewal をつけて強制更新しないと、更新できないので
これをつける。
以下のwebrootモードにしてからね。


0 1 1 * * /home/hideki/certbot/certbot-auto renew --force-renewal && service nginx restart


ssl を切れさせずにサーバー移動した場合、
https://teratail.com/questions/95272

sslをうまく自動更新できない場合がある。
ただ、サーバー移転のたびにssl切れさせるとお客さんの不安を煽るので、
これからはドメイン移転前にssl を入れる方式のが良いかもしれません。

まずは有効期限をチェック
https://comodo.jp/navi/sslchecker

エラー文


Could not choose appropriate plugin: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)
Attempting to renew cert (your.club) from /etc/letsencrypt/renewal/your.club.conf produced an unexpected error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',). Skipping.
The following certs could not be renewed:(failure)
  /etc/letsencrypt/live/your.club/fullchain.pem (failure)


そんな時は以下をやる。
すでにnginxでsslが正常に動いている場合は、nginxの設定は必要無し。
新規ドメイン追加もこれでできる。

1まずは対話スタート

/usr/bin/certbot-auto certonly

2 英語で問われるので、2と入力しEnter。Nginxを使ってますよと答える


How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Apache Web Server plugin - Beta (apache)
2: Nginx Web Server plugin - Alpha (nginx)
3: Spin up a temporary webserver (standalone)
4: Place files in webroot directory (webroot)
-------------------------------------------------------------------------------
Select the appropriate number [1-4] then [enter] (press 'c' to cancel): 

3 更新したいドメイン名を入力

yourdomain.com

4 2と入力しEnter


What would you like to do?
-------------------------------------------------------------------------------
1: Keep the existing certificate for now
2: Renew & replace the cert (limit ~5 per 7 days)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 


んでもって、新しくする


/usr/bin/certbot-auto renew --force-renew
/usr/bin/systemctl restart nginx

で、これで再度有効期限をチェック。
https://comodo.jp/navi/sslchecker

めも

ロードバランサーを使っている場合は、1つずつやってると
「更新しすぎだろエラーがでるので、1つのサーバーに設定したらvpsを落としてコピーコピーが良い。」

サーバー移転する際にhttpsを切らさずにやる。

/usr/bin/certbot-auto certonly --manual --preferred-challenges dns -d vs3.club

すると以下になるので、

Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:

v7XXXXXZZZZYYY111222333444455566677788899VU

Before continuing, verify the record is deployed.

ドメインのDNSサーバーで

TXT _acme-challenge 3600 v7XXXXXZZZZYYY111222333444455566677788899VU

とする。
で、やったらエンターキーを押す。

/etc/letsencrypt/live/vs3.club/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/vs3.club/privkey.pem

追記。
nginxを止めてから更新しないとエラーが出る場合があるみたい。
pythonの文字コードがどうとかいうけど、関係ないようだ。

webrootモードにする

更新する際、webrootモードにするとnginxを止める必要がなくなる。
よって、

上記終わった後に


mkdir /var/www/html/acme/

/home/hideki/certbot/certbot-auto certonly --webroot -w /var/www/html/acme/ -d love-letter.club --agree-tos --force-renewal -n

をやると良いかも。
これで、cronにも設定できるようになる。
じゃないと以下の standalone モードでは cron 仕掛けられないんじゃないかな。

強制更新

/home/hideki/certbot/certbot-auto certonly --standalone -d love-letter.club

nginx 終了させて

/home/hideki/certbot/certbot-auto renew

nginxを再起動。

www 無しを www 付きに統一させる nginx


 /home/hideki/certbot/certbot-auto

そして、ドメイン名の数字を入力し。
次の設問で 1を選ぶ。
(初回の時は、1: Attempt to reinstall this existing certificateってのが出ないがやり直した場合は出る。その時は1を選ぶ。)


ugins selected: Authenticator nginx, Installer nginx

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

5: urap.jp
6: www.urap.jp

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 6
Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/www.urap.jp.conf)

What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Attempt to reinstall this existing certificate
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Keeping the existing certificate
Deploying Certificate to VirtualHost /etc/nginx/conf.d/default.conf
nginx: [warn] conflicting server name "www.urap.jp" on 0.0.0.0:80, ignored

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


ここで 1を選ぶ!

1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
Future versions of Certbot will automatically configure the webserver so that all requests redirect to secure HTTPS access. You can control this behavior and disable this warning with the --redirect and --no-redirect flags.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.urap.jp

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


これでok。


で、リダイレクトする時はこう。


server {

    server_name www.urap.jp;

listen 443 ssl;
listen [::]:443 ssl http2;

ssl_certificate     /etc/letsencrypt/live/www.urap.jp/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.urap.jp/privkey.pem;


rewrite ^ https://urap.jp$request_uri? permanent;


}



nginxを再起動。

25
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
20