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
jrqWJpDdR4HfD76HAgMBAAGjggJTMIICTzAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0l
BBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYE
FD7SztZ59se2884DLM4zdNKaPuBzMB8GA1UdIwQYMBaAFBQusxe3WFbLrl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
-----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
至此证书配置完成!