美文网首页程序员
免费生成https证书,并通过nginx配置

免费生成https证书,并通过nginx配置

作者: 风静花犹落 | 来源:发表于2019-04-21 20:14 被阅读0次

使用 acme.sh 申请 Let's Encrypt 泛域名SSL证书教程

acme.sh 实现了 acme 协议, 可以从 letsencrypt 生成免费的证书.

1. 安装 acme.sh

安装很简单, 一个命令:

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

普通用户和 root 用户都可以安装使用. 安装过程进行了以下几步:

  1. 把 acme.sh 安装到你的 home 目录下:
~/.acme.sh/

并创建 一个 bash 的 alias, 方便你的使用: alias acme.sh=~/.acme.sh/acme.sh

2.生成证书

请先前往阿里云后台获取App_KeyApp_Secret : https://ak-console.aliyun.com/#/accesskey

# 替换成从阿里云后台获取的密钥
export Ali_Key="你的 API KEY"
export Ali_Secret="你的 SECRET KEY"

然后开始生成证书

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

Ali_KeyAli_Secret 信息会保存到 ~/.acme.sh/account.conf 中.

其他dns厂商: https://github.com/Neilpang/acme.sh/wiki/dnsapi

3.安装证书

证书生成以后, 需要把证书 copy 到真正需要用它的地方.

acme.sh --installcert -d example.com -d *.example.com \
        --key-file /etc/nginx/ssl/example/example.com.key \
        --fullchain-file /etc/nginx/ssl/example/fullchain.cer \
        --reloadcmd "nginx -s reload"

nginx配置

server{
        server_name example.com www.example.com;
        listen 80;
        return 301 https://$host$request_uri;
}

server {

        listen  443 ssl http2;
        server_name example.com www.example.com;

        ssl on;
        ssl_certificate /etc/nginx/ssl/example/fullchain.cer;
        ssl_certificate_key /etc/nginx/ssl/example/example.com.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;


       location / {
           proxy_pass http://127.0.0.1:8080;
           root   /var/html/www;
           index  index.html index.htm;
       }
}

4. 更新证书

查看定时任务crontab -l

crontab -l

58 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

目前证书在 60 天以后会自动更新, 你无需任何操作. 今后有可能会缩短这个时间, 不过都是自动的, 你不用关心.

5. 更新 acme.sh

目前由于 acme 协议和 letsencrypt CA 都在频繁的更新, 因此 acme.sh 也经常更新以保持同步.

升级 acme.sh 到最新版 :

acme.sh --upgrade

如果你不想手动升级, 可以开启自动升级:

acme.sh  --upgrade  --auto-upgrade

之后, acme.sh 就会自动保持更新了.

你也可以随时关闭自动更新:

acme.sh --upgrade  --auto-upgrade  0

来源:

https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E

相关文章

网友评论

    本文标题:免费生成https证书,并通过nginx配置

    本文链接:https://www.haomeiwen.com/subject/dmzjgqtx.html