NPMplus Let's Encrypt 憑證續期失效 5 個月:先執行 certbot --dry-run
NPMplus Let's Encrypt renewal dead for 5 months: run certbot --dry-run
NPMplus 的 Let's Encrypt 憑證續期失效,作者執行 certbot renew --dry-run 後,發現 Cloudflare API token 已被撤銷,導致 DNS-01 驗證無法完成。修復 token 後,作者又處理 ACME 帳戶選擇問題,並以每小時檢查實際提供的憑證及 Uptime Kuma push monitor 監察到期情況;憑證有效期約 7 天。
My reverse proxy is NPMplus, a fork of Nginx Proxy Manager. It sits behind my Cloudflare Tunnel and in front of my public hostnames. On 21 September 2026 I found it had stopped, and while I was fixing that I found something worse. Its Let's Encrypt certificate had expired on 24 April 2026. Five months.
Then a week later it expired again.
First, why it was stopped and nobody knew
Quick one, because it's a common trap. The container's restart policy had drifted to no. So when it stopped, Docker just left it stopped. It had happened before, back in July, and I'd fixed it then. It had drifted back since.
The annoying bit: Uptime Kuma was already watching it, and it did go down in Kuma. The alert just never reached anyone. That was a notification gap, not a monitoring gap.
docker update --restart=unless-stopped fixes that without even restarting the container.
The error certbot showed me
Certbot's renewal had been failing every time it ran, and the error it surfaced was about accounts. There were two Let's Encrypt accounts on disk, and unattended certbot wants to know which one: "Please choose an account".
That looks like your answer. Two accounts, it can't pick, renewal stops. Except the renewal config for that cert already named which account to use. So on that cert, the prompt wasn't what was stopping it.
The error that mattered
What found it was the boring thing I should have run first:
certbot renew --dry-run
That gave me the real one:
Error determining zone_id: 9109 Invalid access token
My certs use the DNS-01 challenge through Cloudflare. Certbot uses a Cloudflare API token to create a TXT record, Let's Encrypt checks it, done. The token NPMplus had was revoked. I tend to mint single-purpose Cloudflare tokens for a job and delete them after, and this one had gone the same way, while NPMplus was still relying on it. So renewal could never get past that first step.
The fix, and two traps inside it
I put a working Cloudflare DNS token in (one I'd checked could create and delete a TXT record), and renewal went through. Two things nearly caught me on the way.
1. Don't edit the credentials file. Certbot reads a credentials file inside the container, so the obvious fix is to edit that. But NPMplus writes that file from its own database every time the container starts. Fix the file and it works once, then breaks on the next restart. The token has to go in the cert's row in NPMplus's database.
2. The SQLite WAL trap. NPMplus's database.sqlite has a -wal file next to it. If you copy just database.sqlite out, edit it, and copy it back, SQLite replays the old WAL the next time it opens and your edit quietly disappears. My first DB edit that day looked like it worked and did nothing. What works:
- stop the container
- copy
database.sqlite,-waland-shmout together - open it with
sqlite3(that replays the WAL), make the edit, then runPRAGMA wal_checkpoint(TRUNCATE)to fold it all into the main file - copy the main file back and delete the old
-waland-shm - start the container
One more thing worth knowing. These certs use Let's Encrypt's short-lived profile, so they last about 7 days. Renewal can't fail quietly for a few weeks and catch up later. It has to work every single week.
A week later: expired again
The new cert's expiry was 28 September. On 28 September it expired.
On 8 October I issued a fresh wildcard cert with a DNS token I'd checked actually worked. And this time I dealt with the two ACME accounts as well. When unattended certbot stops at "Please choose an account", the log just says Missing command line flag or config entry. I moved the older account out of the accounts folder and kept the one in use, so there's nothing left for it to ask about.
I'll be honest, I never properly pinned down why the 28 September renewal failed. My notes from that day don't agree with each other on it, so I'm not going to pretend I know. What I take from it is simpler: don't decide from the surfaced error. Run the dry run and read what it says.
Watching it properly
Kuma has a built-in TLS expiry warning, but on a 7-day cert it would basically fire all the time. So I added a small script that runs hourly. It connects and checks the cert that's actually being served, not the files on disk, and pushes to an Uptime Kuma push monitor. It goes DOWN if there's 1.5 days or less left, or if the chain doesn't validate.
On a 7-day cert that renews properly, it never gets close. If renewal breaks, I've got over a day's warning instead of five months.
A related NPMplus gotcha
While I'm here, one that caught me separately. NPMplus does not regenerate its per-host nginx confs when the container restarts. It only rewrites them when you change the host in the UI or API. And if a host has no conf file at all, it won't create one. So if the database and the conf on disk disagree, a restart doesn't fix it. Change the host in the UI, or recreate the container once the database is right.
What I'd do differently
-
Run
certbot renew --dry-runfirst, every time. The surfaced error sent me the wrong way in September. The dry run showed the real one. - Monitor the cert being served, not the renewal job. That's what would have told me in April.
- Give each service its own DNS token. In September I got it going with my Caddy server's token, which meant rotating one would have broken both.
- Don't delete a Cloudflare token until you know what uses it.
- Check alerts reach a person. Kuma saw the proxy go down. Nobody heard.
How do you watch cert renewal on short-lived certs? A 7-day lifetime changes what "good enough" monitoring looks like.
🤖 Drafted with AI assistance from my own homelab notes, logs and repos, and fact-checked against them before publishing.
來源:DEV Community · dev.to

