Files
Deployments/acme

前期准备

主要是接下来安装acme时的gfw问题。如果是境内服务器则有可能需要如下步骤。

  1. 小飞机的局域网内的代理地址。因为get.acme.sh中包含的脚本请求地址可能会被墙

    export http_proxy="172.18.184.139:10082"

    export https_proxy="172.18.184.139:10082"

  2. 是因为据说在此加入上面的export命令可以实现开机自动开启代理。但没有尝试

vim /etc/bashrc

  1. 同上

vim /etc/profile

安装acme

  1. 安装acme

    curl https://get.acme.sh | sh

    安装完毕后关闭这个连接的console再重新打开。

  2. 将dns api的key和secret存入环境变量。此处为阿里云事前已经给对应SAM子账户分配了FullDnsApiAccess的权限。参见 https://blog.csdn.net/chen249191508/article/details/98088553

    export Ali_Key="key"

    export Ali_Secret="secret"

    参见保密区域获取真实内容。注意阿里云的控制台中这两个值只在添加SAM子账户的时候出现需要马上自行保存

获取证书

  1. 申请安装证书。加--debug参数可以显示更多细节

    acme.sh --debug --issue --dns dns_ali -d dev.woyue.org -d *.dev.woyue.org

  2. 安装完毕后,检验是否配置自动任务

    crontab -e

  3. 确认当前证书

    acme.sh --list

安装证书

  1. 复制证书:

    场景1

    mkdir -p /srv/certbot/conf/live/dev.woyue.org

    acme.sh --installcert -d dev.woyue.org -d *.dev.woyue.org
    --key-file /srv/certbot/conf/live/dev.woyue.org/privkey.pem
    --fullchain-file /srv/certbot/conf/live/dev.woyue.org/fullchain.pem
    --reloadcmd "docker restart nginxdocker_nginx_1"

    场景2

    mkdir -p /srv/certbot/conf/live/nr.woyue.org

    acme.sh --installcert -d nr.woyue.org -d *.nr.woyue.org
    --key-file /srv/certbot/conf/live/nr.woyue.org/privkey.pem
    --fullchain-file /srv/certbot/conf/live/nr.woyue.org/fullchain.pem
    --reloadcmd "docker restart nginx"

    注意最后的nginxdocker_nginx_1为nginx容器的名称。请根据实际情况修改。或不加此参数手动重启nginx

  2. 生成dhparams文件

    openssl dhparam -out /srv/certbot/conf/ssl-dhparams.pem 2048

使用证书

例如要使用上述证书则nginx的docker对应etc/letsencrypt的目录就是/srv/certbot/conf。比如说conf文件里引用的密钥文件路径为

ssl_certificate /etc/letsencrypt/live/nr.woyue.org/fullchain.pem

那么docker mount的路径就应该是-v /srv/certbot/conf:/etc/letsencrypt