certbot certonly 自动获取证书非80端口的坑

warning: 这篇文章距离上次修改已过230天,其中的内容可能已经有所变动。
  • 一个网站项目,采用caddy+tls来实现https和证书自动获取,由于项目不对外,所以希望越少人知道越好,故部署后把80端口禁了,443端口改成了其他。开始运行正常,但是过了一段时间后,发现网页打开提示证书过期。这个就很奇怪了,证书怎么会过期呢,certbot不是会自动续期吗。
  • journal -xefu caddy 查看caddy运行日志,发现certbot 请求都会有authorize faile之类的提示。但是我对项目并没有任何改动。之后就是各种折腾,更换邮箱,删除caddy证书,再certbot 重新配置证书,但都没有效果。
  • 最后无意中看到certbot certonly配置完后,请求证书前校验的域名信息,域名是http://xxx.com/xxxxxxxx 。然后信息显示如下:

    
    Detail: 198.98.60.174: Fetching http://xxx.com/.well-known/acme-challenge/J5RAi0k_iFcyLan_sL7XHlT5NG8UXRzgOUA894VEU1E: Timeout during connect (likely firewall problem)
    
    Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.

    那显然是访问不到的,因为我把80端口给屏蔽了,于是把它开起来,不一会儿加https就能正常访问项目了。

  • 后来查了下资料,发现用以下命令可以手动添加和校验
    certbot certonly --manual
  • 还有一种说法是用dns就可以自动续期,==可以不用80,但没亲测== update:2023-09-10 亲测有效详则这里《用cerbot自动更新docker里caddy的证书》。
    certbot certonly --preferred-challenges dns --manual -d xxx.com
none
最后修改于:2023年09月10日 01:34

评论已关闭