Posted in: IT, Website/Blog

博客搬家到 VPS

背景

之前博客是放在香港的虚拟主机上,有些功能就用不了(例如对象缓存 Object Cache)。虽然也有过转移到 VPS 的想法,但香港的 VPS 用的人太多,时不时感觉不稳定。再加上付款周期还没到,就搁置了。

前几天在网上看到日本有冷门的 VPS(需要本地手机号和住址验证),走的 IIJ 线路。正好上面有个免费 14 天试用,就申请试了一下,感觉连接国内速度还行(不绕路),就决定正式申请了。顺便花了一天时间把博客搬了过来。

Posted in: Website/Blog

SSL 风波

我的 SSL 证书是主机供应商提供自动续期的,从上个月中旬开始第一期到期,去后台查看发现已经确认自动续期,但是不知为什么我自己访问站点时,时不时提示 SSL 证书过期,显示还是之前的老证书。这个“时不时”很诡异,大约三次里面两次失败一次成功。

折磨了将近两星期,向主机供应商发工单前后七八次,依旧无果。直到老麦兄在留言中提醒:“关了代理能正常访问”。我马上意识到是 CDN 的问题。

Posted in: IT, Website/Blog

利用 certbot 给Let’s Encrypt SSL 续期的两种方法

国内主机:推荐 DNS 法来手动续期

国内主机由于对Let’s Encrypt官网连接经常出现问题,因此推荐 DNS 法手动续期。特别是默认的 certbot renew 命令很容易由于网络连接问题导致失败,此时千万不要反复尝试,否则失败多次后直接封你一个星期没商量。惨痛教训。 😥

DNS验证是比较安全的方法,具体参考这篇文章。在此备份一下命令:

# certbot --manual --preferred-challenges dns certonly

然后有两个地方需要注意的,文章没提到:

第一:添加DNS时千万要仔细看清楚域名写的是什么,不是简单一个_acme-challenge 就完事了,因为可能有子域名。

第二:成功之后最好重启一下httpd服务。

这种方法每三个月都得手动操作一次,不能自动

国外主机:推荐 snap 自动续期

snap 的官方全文在此处。其实也没什么特殊的,事实上就是它自动帮你安装了一个list-timers脚本,无需手动去设置cron。

webroot 的坑

官方原文里讲了standalone和webroot两种模式,什么区别呢?比如我的博客 URL 是 https://springwood.me ,用的443端口,不需要80端口。但实际上我必须得用80端口来承接 http://springwood.me,然后重定向到 443 的 https,这种情况下就不能使用standalone模式了,要用webroot。

官方原文里有一个没有提到的坑是:用 --webroot 时必须用 -w 加上具体的目录名字,例如:

# certbot certonly --webroot -w /var/www/html

这里的 /var/www/html/ 是你的域名对应的根目录

然后去看一下 /etc/letsencrypt/renewal/yourdomain.com.conf,最后几行应该是:

[renewalparams]
account = XXXXXXXX
authenticator = webroot
server = https://acme-v02.api.letsencrypt.org/directory
key_type = rsa
webroot_path = /var/www/html,
[[webroot_map]]

这样就对了。

此时可以 certbot renew --dry-run尝试一下。

如果最开始用 --webroot 时没有用 -w 加上具体的目录名字, certbot renew --dry-run就会出现如下错误:

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/yourdomain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for yourdomain.com
Failed to renew certificate yourdomain.com with error: Missing command line flag or config entry for this setting:
Input the webroot for yourdomain.com:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/yourdomain.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

刚才在这坑里折腾了很久。

Back to Top