申请Https证书有多种方法,这里主要说两种:certbotacme.sh

Certbot —— 官方钦点方式

下载certbot

SSL证书有多个级别,价格上有免费到上千不等,如果只是一个个人站点、博客,那么使用certbot下的免费证书就好了。

# 获取certbot
wget https://dl.eff.org/certbot-auto --no-check-certificate

# 给予运行权限
chmod a+x certbot-auto

申请证书

# 运行certbot
./certbot-auto --manual certonly

根据提示输入邮箱和域名,然后再在相应的目录下面创建文件,即可生成证书文件,在输出日志中会显示生成的路径

生成的证书只有3个月的有效期,三个月后需要重新激活

# 重新激活
./certbot-auto renew

如果嫌麻烦,运行下面命令可以定期自动激活

# 定期自动激活
./certbot-auto renew --dry-run

acme.sh —— 更推荐的方式

安装acme.sh

# 下载acme.sh
curl  https://get.acme.sh | sh
# 或者
wget -O - https://get.acme.sh | sh

#设置脚本别名,简化使用
cd ~/.acme.sh
alias acme.sh=~/.acme.sh/acme.sh

# 安装acme.sh
./acme.sh --install --home 安装目录
# 更新acme.sh
./acme.sh --upgrade

申请证书

此处演示dnsapi使用dnspod,使用时请更换为你自己的dnsapi,dnsapi具体用法见acme.sh dnsapi

#在dnspod里生成自己的api
export DP_Id="改成你自己的api-id"
export DP_Key="改成你自己的api-token"
#生成证书
acme.sh  --issue   --dns dns_dp   -d yourdomain.com

#证书拷贝
acme.sh  --installcert  -d  yourdomain.com   \
        --key-file   /home/ssl/yourdomain.com.key \
        --fullchain-file /home/ssl/fullchain.cer

参考

acme.sh中文文档
用Certbot 获取和自动更新SSL证书
How to install acme.sh
acme.sh dnsapi

Q.E.D.


此 生 无 悔 恋 真 白 ,来 世 愿 入 樱 花 庄 。