手把手教你搭建HTTPS证书,自动更新

自己的服务器,配置nginx,需要搭建https证书,之前都是手动去阿里云申请免费证书 ,现在记录一下,自动部署,更新https证书

1、安装 yum-utils

yum-utils is a collection of tools and programs for managing yum repositories, installing debug packages, source packages, extended information from repositories and administration.

yum -y install yum-utils

yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

yum install certbot python2-certbot-nginx

工具装好之后,就可以获取证书了

2、自动获取证书+安装+配置

#nginx-server-root nginx配置文件
#-d = 你要配置的域名
certbot --nginx --nginx-server-root=/usr/local/nginx/conf/ -d=you_domain

会有提示,是否提供邮箱,咱们不提供吧

还有是否http 重定向到https,也直接选择1

就此完成了。

 

接下来还需要编写一个脚本自动来更新你的HTTPS证书

执行下面命令就好了

echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章