首页 服务器技术 nginx

acme.sh证书自动申请|dns_ali修改nginx

acme.sh 证书自动申请


# 下载 acme.sh

git clone --depth 1 https://github.com/acmesh-official/acme.sh.git

# 安装acme.sh

cd acme.sh && acme.sh --install  && acme.sh --register-account -m benma9@qq.com

# 增加aws的 access_key认证


# 首次申请证书,使用aws 的 route53, 前提域名申请的账户跟域名的关系要确定

https://github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_aws

export  AWS_ACCESS_KEY_ID=""

export  AWS_SECRET_ACCESS_KEY=""

./acme.sh --issue --dns dns_aws -d example.com -d *.example.com 

如果失败记得清理 

'_acme-challenge' 的所有记录

如果是ali的参考,目前支持100多个dns服务商

https://github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_ali


# 修改nginx的配置 example.com 替换成申请的证书


server {

    listen       443 ssl;

    server_name  example.com;

    root         /var/www/app/;

        ssl_certificate "/root/.acme.sh/example.com_ecc/fullchain.cer";

        ssl_certificate_key "/root/.acme.sh/example.com_ecc/example.com.key";

        ssl_session_cache shared:SSL:1m;

        ssl_session_timeout  10m;

        ssl_ciphers HIGH:!aNULL:!MD5;

        ssl_prefer_server_ciphers on;

        keepalive_timeout 600;

        index index.html;

    location / {

        try_files $uri $uri/ @router;

        index index.html;

    }

    location @router {

        rewrite ^.*$ /index.html last;

    }

}

# 增加crontab 定时更新nginx的配置文件,以下是docker的nginx

55 22 * * * docker ps|grep nginx| awk '{print $1}'| xargs -I {} docker exec {} nginx -s reload

相关推荐