手把手教你搭建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

 

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