Let's Encrypt泛域名证书申请

   |   2 minute read   |   Using 525 words

acme.sh实现了acme协议,可以从let’s encrypt方便的生成免费https证书,最主要因为let’s encrypt的证书都是有有效期的,过期以后需要手动续期,而acme.sh会为你生成一个定时cron计划任务,这样就可以自动检测证书是否到期,快到期就会自动为你重现申请证书,避免了自己忘记证书过期时间而没用重新申请的尴尬。

使用acme.sh脚本申请Let’s Encrypt泛域名SSL证书

首先安装acme.sh

curl https://get.acme.sh | sh

执行以上命令后会在用户的Home目录下自动生成一个名为 .acme.sh 的隐藏目录,以后acme.sh脚本的所有执行结果数据都放在此目录中,不会扰乱你自己的目录结构。

source ~/.bashrc

设置DNS API,acme.sh验证域名时会用此验证

可从域名解析商后台查询相关API Key,acme.sh支持多个平台的域名解析验证,此文以cloudflare解析为例。

export CF_Key="jflajfajsfljsdfjlskfjlsf"

export CF_Email="[email protected]"

开始申请签发证书

acme.sh --issue --dns dns_cf -d *.example.com

申请成功后会提示证书的绝对路径(都在用户Home目录下的.acme.sh子目录内),接下来就可以拷贝证书到Web服务器对应的目录并配置启用HTTPS了。

Nginx配置HTTPS

server {
    
    listen 443 ssl;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_certificate /where/is/your/.acme.sh/*.example.com/fullchain.cer;
    ssl_certificate_key /where/is/your/.acme.sh/*.example.com/*.example.key;

    server_name www.example.com;
    
    set     $root_path '/www/www.example.com';
    root    $root_path;
    
    ... ...
}    


comments powered by Disqus