使用acme.sh免费申请证书

国内服务器:

git clone https://gitee.com/neilpang/acme.sh.git
cd acme.sh
./acme.sh --install -m my@example.com

海外服务器:

wget https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh
./acme.sh --install -m my@example.com

自动为你创建 cronjob, 每天 0:00 点自动检测所有的证书, 如果快过期了, 需要更新, 则会自动更新证书,安装过程不会污染已有的系统任何功能和文件, 所有的修改都限制在安装目录中: ~/.acme.sh/

生成证书:

Tips:acme指定CA机构:/root/.acme.sh/acme.sh –set-default-ca –server letsencrypt

https://github.com/acmesh-official/acme.sh/wiki/Server

acme.sh实现了acme协议支持的所有验证协议.

一般有两种方式验证: http 和 dns 验证.

如果你用的nginx服务器, 或者反代,acme.sh还可以智能的从nginx的配置中自动完成验证, 你不需要指定网站根目录:

apt-get install nginx

/etc/nginx/sites-enabled/default:

Tips:server_name要设置为跟/root/.acme.sh/acme.sh –issue -d <domain_name>一样的域名,如果不一样的话,配置文件识别不了

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name eset.update.apollo-sun.online;
        location / {
                try_files $uri $uri/ =404;
        }
}

Tips:解析域名eset.update.apollo-sun.online到本服务器IP上,如果不解析的话,(The CA is processing your order)验证不了

/root/.acme.sh/acme.sh --issue -d eset.update.apollo-sun.online --nginx /etc/nginx/sites-enabled/default

Tips:以上方式的好处是可以自动更新证书:

手动DNS方式:

Tips:手动在域名上添加一条 txt 解析记录, 验证域名所有权.

这种方式的好处是, 你不需要任何服务器, 不需要任何公网 ip, 只需要 dns 的解析记录即可完成验证.

坏处是,如果不同时配置 Automatic DNS API,使用这种方式 acme.sh 将无法自动更新证书,每次都需要手动再次重新解析验证域名所有权。

acme.sh –issue –dns -dmydomain.com –yes-I-know-dns-manual-mode-enough-go-ahead-please

然后,acme.sh会生成相应的解析记录显示出来, 你只需要在你的域名管理面板中添加这条 txt 记录即可.

等待解析完成之后, 重新生成证书:

acme.sh –renew -dmydomain.com –yes-I-know-dns-manual-mode-enough-go-ahead-please 

dns 方式的真正强大之处在于可以使用域名解析商提供的 api 自动添加 txt 记录完成验证.

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

acme.sh目前支持 cloudflare, dnspod, cloudxns, godaddy 以及 ovh 等数十种解析商的自动集成.以 dnspod 为例, 你需要先登录到 dnspod 账号, 生成你的 api id 和 api key, 都是免费的.

export DP_Id="1234"




export DP_Key="sADDsdasdgdsf"




acme.sh   --issue   --dns dns_dp   -d aa.com  -d www.aa.com

证书就会自动生成了. 这里给出的 api id 和 api key 会被自动记录下来, 将来你在使用 dnspod api 的时候, 就不需要再次指定了.

直接生成就好了:

acme.sh --issue -d mydomain2.com --dns dns_dp

Use Aliyun domain API to automatically issue cert

First you need to login to your Aliyun account to get your RAM API key.https://ram.console.aliyun.com/users

export Ali_Key="<key>"
export Ali_Secret="<secret>"

Ok, let’s issue a cert now:

./acme.sh --issue --dns dns_ali -d www.example.com

The Ali_Key and Ali_Secret will be saved in ~/.acme.sh/account.conf and will be reused when needed.

文件名内容
cert.pem服务端证书
chain.pem浏览器需要的所有证书但不包括服务端证书,比如根证书和中间证书
fullchain.pem包括了cert.pem和chain.pem的内容
privkey.pem证书的私钥

使用alidns的api申请SSL证书:

#!/bin/bash
export Ali_Key=""
export Ali_Secret=""
Domain="iftop.top"
Host=$1
./acme.sh --issue --force --dns dns_ali -d "$Host.$Domain"
Categories: 系统运维