Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用acme.sh自动阿里云DNS反向代理letsencrypt生成ssl证书 #6

Open
lihui546682631 opened this issue Apr 1, 2022 · 1 comment

Comments

@lihui546682631
Copy link

lihui546682631 commented Apr 1, 2022

2022-04-01 letsencrypt自动阿里云DNS反向代理问题的处理步骤

一、问题描述与思路

今日发现自己的小破站提示证书到期访问不了了,遂检查Neilpang/letsproxy的运行情况,发现不知何故证书没更新成功,尝试容器重启无果,删除配置重新生成,此时又报验证域名归属失败
再经过多种尝试无果后只能将手伸进容器里面动acme.sh的更新脚本updatessl.sh了,原内容

#!/usr/bin/env sh

_SCRIPT_="$0"

ACME_BIN="/acme.sh/acme.sh --home /acme.sh --config-home /acmecerts"

DEFAULT_CONF="/etc/nginx/conf.d/default.conf"

CERTS="/etc/nginx/certs"

updatessl() {
  nginx -t && nginx -s reload
  if grep ACME_DOMAINS $DEFAULT_CONF ; then
    for d_list in $(grep ACME_DOMAINS $DEFAULT_CONF | cut -d ' ' -f 2);
    do
      d=$(echo "$d_list" | cut -d , -f 1)
      $ACME_BIN --issue --server letsencrypt --ocsp -k ec-256 \
      -d $d_list \
      --nginx \
      --fullchain-file "$CERTS/$d.crt" \
      --key-file "$CERTS/$d.key" \
      --reloadcmd "nginx -t && nginx -s reload"
    done

    #generate nginx conf again.
    docker-gen /app/nginx.tmpl /etc/nginx/conf.d/default.conf
  else
    echo "skip updatessl"
  fi
  nginx -t && nginx -s reload
}

"$@"

遍读脚本发现内部操作大致分为3步
1.遍历所有配置的域名生成证书,使用/acme.sh/acme.sh
2.使用docker-gen /app/nginx.tmpl /etc/nginx/conf.d/default.conf生成nginx配置
3.nginx -t && nginx -s reload

此前了解由于新版letsencrypt验证域名归属的步骤变得复杂了,需要在自己域名下放一个验证文件,并且外网可访问才行,所以用acme.sh处理时验证归属失败就无法生成证书,由于我的域名是阿里云的,备案过的,可以使用acme.sh中dns解析模式
dns解析原理是自动访问解析接口添加txt解析,然后再由acme.sh自动验证域名归属,此时就能通过了

二、操作步骤

1. 阿里云用户配置

进入阿里云后台添加用户,添加完用户后记下以下信息
AccessKey ID
AccessKey Secret
添加用户组,并添加用户组的用户和权限,权限添加可搜索dns和解析关键字,全添加即可

2. 容器配置

根据acme.sh/wiki/dnsapi方法添加配置到~/.acme.sh/account.conf(容器运行时映射出来)

然后使用命令 acme.sh --issue --dns dns_ali -d <domain> --nginx --fullchain-file "<crtfile>" --key-file "<keyfile>"生成

进入Neilpang/letsproxy容器 docker-compose exec nginx bash 我的容器名就是nginx,请自行修改
运行命令1 /acme.sh/acme.sh --home /acme.sh --config-home /acmecerts --issue --server letsencrypt --ocsp -k ec-256 --dns dns_ali -d git.6sp.site --nginx --fullchain-file "/etc/nginx/certs/git.6sp.site.crt" --key-file "/etc/nginx/certs/git.6sp.site.key" --reloadcmd "nginx -t && nginx -s reload"
运行命令2 docker-gen /app/nginx.tmpl /etc/nginx/conf.d/default.conf
运行命令3 nginx -t && nginx -s reload
最后exit退出容器

请大佬指点

@SHctt
Copy link

SHctt commented Aug 4, 2022

有没有检查防火墙设置

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants