Letsencrypt certbot命令的默认操作使得网站在Android端报证书错误的问题

Letsencrypt乃HTTPS时代的一大良心产品,其良心不仅在于免费提供不用自己安装根证书的HTTPS签名,更在于为各主流Linux发行版提供了软件包,理论上几个命令就可以完成网站签名,并且自动修改nginx配置文件。

不过,我前段时间在树莓派上用Letsencrypt提供的certbot工具对本站进行签名时,发现了这工具的默认行为有点怪:签名成功后,一共提供了四个签名文件,并且还提供了README文件:

This directory contains your keys and certificates.

`privkey.pem`  : the private key for your certificate.
`fullchain.pem`: the certificate file used in most server software.
`chain.pem`    : used for OCSP stapling in Nginx >=1.3.7.
`cert.pem`     : will break many server configurations, and should not be used
                 without reading further documentation (see link below).

WARNING: DO NOT MOVE OR RENAME THESE FILES!
         Certbot expects these files to remain in this location in order
         to function properly!

We recommend not moving these files. For more information, see the Certbot
User Guide at https://certbot.eff.org/docs/using.html#where-are-my-certificates.

奇怪之处在于,certbot它自己明明说了cert.pem这个文件“will break many server configurations”,但它在默认设置下偏偏就把这个文件用到了nginx配置文件的ssl_certificate字段中。后果倒是不严重:由于PC浏览器多数已经内置了对于Letsencrypt证书的信任,所以访问没啥问题。但移动的浏览器尤其是Android,访问这网站时就会弹警告说证书不对,一些客户端类工具如Joplin则直接报错(还报的是”网络连接失败“这种不明所以的错)。

Android端报错的原因是证书链不对,简单来说就是cert.pem这个文件缺了一些内容。更正方法是在nginx配置文件中,将ssl_certificate字段指向的文件地址,由cert.pem修改到同目录下的fullchain.pem.

    #ssl_certificate /etc/letsencrypt/live/www.tiger2doudou.com/cert.pem;
    #上面一行修改为
    ssl_certificate /etc/letsencrypt/live/www.tiger2doudou.com/fullchain.pem;

    ssl_certificate_key /etc/letsencrypt/live/www.tiger2doudou.com/privkey.pem;
    
    ......

然后重启nginx,Android端应该就不报错了。

前面链接里教了可以通过手动操作补全,但Letsencrypt证书需要每90天更新,每次操作就太麻烦了。

PS:这就是中间证书的问题,TrustAsia的证书也出了一次这问题,点此进入

  • 最后更改: 2020/08/27 07:21