ssl:Ubuntu安装免费ssl证书实现https访问
服务器系统为Ubuntu 16.04。
安装 certbot:
root$ sudo apt-get update
root$ sudo apt-get install software-properties-common
root$ sudo add-apt-repository ppa:certbot/certbot
root$ sudo apt-get update
root$ sudo apt-get install certbot
root$ certbot --version
以命令交互方式开始制作证书(要先停止nginx、apache等服务:root$ sudo systemctl stop nginx):
root$ certbot certonly
后面根据提示操作
证书定时更新:
证书有效期只有三个月,到期前可以使用certbot-auto来更新。
可以先加入 --dry-run 參數,先進行測試。(测试发现还是要先停止nginx解除80端口占用才能成功)
sudo certbot renew --dry-run
如果成功则可以设置一个定时任务来定时执行更新。
0 4 30 * * sudo systemctl stop nginx # 停止nginx解放80端口 每月30日早上四点整执行
1 4 30 * * sudo certbot renew #更新证书 每月30日早上四点01执行
2 4 30 * * sudo systemctl start nginx #启动nginx 每月30日早上四点02执行
crontab时间设置计算器工具: https://crontab.guru/