安装ACME客户端
yum install socat
curl https://get.acme.sh | sh
阿里云后台创建子账号
给刚刚创建的子账号添加权限
将获取到的AccessKey 和 Secret 写到acme.sh.env配置文件里面
vim /root/.acme.sh/acme.sh.env
修改后acme.sh.env文件变成:
export LE_WORKING_DIR="/root/.acme.sh"
alias acme.sh="/root/.acme.sh/acme.sh"
export Ali_Key="*****“
export Ali_Secret=”*******"
执行source 命令
source ~/.bashrc
执行env命令查看环境变量,可以查看到刚刚配置的ali_key 跟 ali_secret
切换CA机构到letsencrypt:
acme.sh --set-default-ca --server letsencrypt
执行命令:
acme.sh —issue —dns dns_ali -d .xxx.com -d '.xxx.com’
顺利的话就能看到生成的通配符ssl证书
拿到证书后就能配置到nginx
server {
listen 443;
ssl on;
ssl_certificate /root/.acme.sh/xxx.com/fullchain.cer;
ssl_certificate_key /root/.acme.sh/xxx.com/xxx.com.key;
server_name *.xxx.com;
location / {
proxy_pass http://*****;
proxy_set_header Host $host;
proxy_set_header Connection close;
proxy_connect_timeout 60s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
access_log /data/logs/nginx/access.log;
error_log /data/logs/nginx/error.log;
}
检查一下看看有没有问题
nginx -t
没有问题就执行
nginx -s reload