重新生成SSL证书之后的问题
markdown
## 问题
最近SSL证书到期了, 正常情况下可以用以下命令续租:
```
sudo /etc/init.d/apache2 stop
certbot renew
sudo /etc/init.d/apache2 start
```
但是我的Blog从服务器中摘除了, 所以要生成新的证书:
```
sudo /etc/init.d/apache2 stop
sudo certbot certonly --standalone -d xxx.xxx.xxx...
sudo /etc/init.d/apache2 start
```
成功, 但是SSL还是显示失效
## 解决方法
用一个没有DNS代理的二级域名, 上去看看, 发现SSL证书没有用最新的


登录服务器, 查看证书目录, 果然多了一个
```
ll /etc/letsencrypt/live/
drwx------ 5 root root 4096 Oct 23 10:41 ./
drwxr-xr-x 9 root root 4096 Oct 23 01:51 ../
-rw-r--r-- 1 root root 740 Feb 24 2022 README
drwxr-xr-x 2 root root 4096 Oct 23 10:51 xxx.xxx-0001/
drwxr-xr-x 2 root root 4096 Jul 24 03:17 xxx.xxx/
ll /etc/letsencrypt/archive/
drwx------ 4 root root 4096 Oct 23 10:40 ./
drwxr-xr-x 9 root root 4096 Oct 23 01:51 ../
drwxr-xr-x 2 root root 4096 Oct 23 01:51 xxx.xxx-0001/
drwxr-xr-x 2 root root 4096 Jul 24 03:17 xxx.xxx/
```
通过日期可以发现, 0001是新的, 但是生成证书时为什么多了一个0001, 而没有覆盖, 不太清楚
我们通过把它备份, 改下名:
```
vim /etc/apache2/sites-available/default-ssl.conf # 确认证书的文件夹是/etc/letsencrypt/live/xxx.xxx
cd /etc/letsencrypt/
mv ./archive/xxx.xxx ./archive/xxx_bk.xxx
mv ./archive/xxx.xxx-0001 ./archive/xxx.xxx
mv ./live/xxx.xxx ./live/xxx_bk.xxx
mv ./live/xxx.xxx-0001 ./live/xxx.xxx
```
然后开启apache2, 但是报错
```
sudo /etc/init.d/apache2 start
Starting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
```
按照提示, 我们使用命令查看情况
```
systemctl status apache2.service
```
结果提示在 ./live/xxx.xxx 里的软链接找不到对应的文件, 原来是里面的软链接还链接这老命名的文件, 例如:
```
cert.pem -> ../../archive/xxx.xxx-0001/cert2.pem
```
使用以下命令重新链接以下就可以了:
```
cd /etc/letsencrypt/live/xxx.xxx/
ln -f -s ../../archive/xxx.xxx/cert2.pem cert.pem
ln -f -s ../../archive/xxx.xxx/chain2.pem chain.pem
ln -f -s ../../archive/xxx.xxx/fullchain2.pem fullchain.pem
ln -f -s ../../archive/xxx.xxx/privkey2.pem privkey.pem
```
然后启动apache2, 完成
评论
发表评论