ACME

ACME

简介

Automatic Certificate Management Environment (ACME) 协议是一种通信协议,用于自动化生成和续期 SSL 证书。

安装

使用如下命令即可完成安装:

1
curl https://get.acme.sh | sh -s email=<email>

签发证书(独立签发)

如果没有 nginx 服务器则使用如下命令:

1
2
yum install -y socat
acme.sh --issue -d <domain> --standalone

签发证书(Nginx)

先编写基础的服务配置文件:

1
2
3
4
5
6
7
8
server {
listen 80;
server_name xxx.xxx.xxx.xxx;

location /.well-known/acme-challenge/ {
root /usr/share/nginx/xxx;
}
}

然后测试配置文件并启动 Nginx:

1
2
nginx -t
systemctl enable nginx --now

然后再使用如下语句即可签发证书:

1
acme.sh --issue -d <domain> --nginx

安装证书

签发完成后可以修改 Nginx 配置文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {
listen 80;
server_name xxx.xxx.xxx;

location /.well-known/acme-challenge/ {
root /usr/share/nginx/xxx;
}

return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name xxx.xxx.xxx;
client_max_body_size 5M;
ssl_certificate /etc/nginx/ssl/xxx-cert.pem;
ssl_certificate_key /etc/nginx/ssl/xxx-key.pem;

location / {
proxy_pass http://xxx.xxx.xxx.xxx;
}

location /static {
alias /usr/share/nginx/xxx-static;
}
}

然后使用如下命令,将签发完成的证书转存至 Nginx 配置目录中去:

注:此外 acme 还会启动定时任务,自动刷新续期。

1
2
3
4
acme.sh --install-cert -d xxx.xxx.xxx \
--key-file /path/to/keyfile/in/nginx/key.pem \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd "service nginx force-reload"

其他指令

查看证书相关信息:

1
acme.sh --info -d <domain>

查看当前的域名清单:

1
acme.sh --list

手动强制刷新域名有效期:

1
acme.sh --renew -d <domain> --force

参考资料

维基百科

acme.sh 官方项目


ACME
https://wangqian0306.github.io/2023/acme/
作者
WangQian
发布于
2023年4月28日
许可协议