acme证书安装,免费给网站配置https证书

该博客详细介绍了如何通过acme.sh脚本,结合GoDaddy DNS API,自动化申请并配置SSL证书的过程。步骤包括下载脚本、设置环境变量、使用DNSAPI申请证书、修改Nginx配置以及设置定时任务更新证书。教程中还展示了成功申请证书后的输出示例。
摘要由CSDN通过智能技术生成

1.下载脚本

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

2.配置环境变量

alias acme.sh=~/.acme.sh/acme.sh

3.使用dns api方式申请

需要登陆 https://developer.godaddy.com/keys 申请key
拿到key后将key替换以下命令执行:

export GD_Key="这里放key"
export GD_Secret="这里放secret"
acme.sh --issue --dns dns_gd -d xxx.com -d '*.xxx.com'  --debug
acme.sh --issue --dns dns_gd -d xxx.com -d www.xxx.com 

上面想xxx.com替换为真实想配置的域名
如出现以下结果则表示执行成功:

[Thu May  6 15:56:24 CST 2021] Cert success.
-----BEGIN CERTIFICATE-----
MIIFKDCCBBCgAwIBAgISBOtkoZUBMIe1vCCtIqPhm6UlMA0GCSqGSIb3DQEBCwUA
MDIxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQD
EwJSMzAeFw0yMTA1MDYwNjU2MjNaFw0yMTA4MDQwNjU2MjNaMBUxEzARBgNVBAMT
CjRpdG9vbC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC/mkYl
h31Y0le7p/RY57DV7WENR+AjwDQ97/QgCOrN54uzispsoo+QD1oXQybV99flzvfB
KuI0L3UMxA6kPiTXlzj4Nxka96HcxqNYn4fjbHPqES6hX7RXh6dtPse13YeUJGn+
cEHAXpaY6KJOsaPxjEJNiVhPpuCmkKEXiCf1FDrzwtuKjCwm6hXUEJaT5klylcdo
LNibMM7C+fY4S5dGn3F8nblbwlv+TUODl4MGCs8lP1btfk6n97FH5n79SBqSl2jM
8lqeZqdkJ+a39qW24SrVAZl+vahymVzVd9Y2pxK/p4QIAxvz54m4UBKCJ/+/gpoe
jrqWJpDdR4HfD76HAgM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jV8KIEB2FgbVtSW8KEmHeEt/hQ6ddo6vE1T32KKPD2tTV7BRq1xW0B/cddFte/
UDmmLHrTMVnWlaN7zkE6YwNIl6n6Ajg64Lsq5r+rbxHEKL0KkJv39LXdMh0YppwD
VS7mX6e4ONt3MREjSobBHM7ZGZyVkPeeD9IBDw==
-----END CERTIFICATE-----
[Thu May  6 15:56:24 CST 2021] Your cert is in  /root/.acme.sh/xxx.com/xxx.com.cer 
[Thu May  6 15:56:24 CST 2021] Your cert key is in  /root/.acme.sh/xxx.com/xxx.com.key 
[Thu May  6 15:56:24 CST 2021] The intermediate CA cert is in  /root/.acme.sh/xxx.com/ca.cer 
[Thu May  6 15:56:24 CST 2021] And the full chain certs is there:  /root/.acme.sh/xxx.com/fullchain.cer 

4.修改nginx

server {
        listen 443 ssl;
        server_name  www.xxx.com;
        root  /home/www/xxx;
        error_log  /home/wwwlogs/xxx.error.log;
        access_log  /home/wwwlogs/xxx.acc.log;
        # 修改下面两行代码后面的证书路径即可
        ssl_certificate /root/.acme.sh/xxx.com/fullchain.cer;
        ssl_certificate_key /root/.acme.sh/xxx.com/xxx.com.key;
        location / {
            index  index.html index.htm;
        }
         location /nginx_status
        {
            stub_status on;
            access_log   on;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }
}
server {
        listen 80;
        server_name www.xxx.com;
        if ($host = www.xxx.com) {
             return 301 https://$host$request_uri;
        }
        if ($host = xxx.com) {
             return 301 https://www.$host$request_uri;
        }
}

5.定时任务更新证书

53 0 * * * /root/.acme.sh/acme.sh --cron --home /root/.acme.sh --force > /dev/null

至此证书配置完成!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Venvis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值