Let's Encrypt 泛域名证书申请与安装

Let’s Encrypt 泛域名证书申请与安装

使用“让我们加密”配置和保护Nginx的步骤

使用“让我们加密”保护Nginx的过程如下:

  1. 获取acme.sh软件以获取SSL证书:
    git clone https://github.com/Neilpang/acme.sh.git
  2. 创建/.well-known/acme-challenge/目录:
    mkdir -p /var/www/.well-known/acme-challenge/
  3. 获取域的SSL证书:
    acme.sh –issue -w /DocumentRootPath/ -d your-domain
  4. 在Nginx Web服务器上配置TLS / SSL:
    vi /etc/nginx/sites-available/default
  5. 验证您域的自动续订Cron作业设置
  6. 打开端口443(HTTPS):
    ufw allow proto tcp from any to server-IP-here port 443

安装acme.sh

首先,使用apt-get命令apt命令安装git和bc软件包:
$ sudo apt-get install git bc wget curl socat

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

为theos.in域颁发证书

语法如下, 其中,
acme.sh --issue -w /DocumentRootPath/ -d example.comacme.sh --issue -w /DocumentRootPath/ -d www.bar.com -d bar.comacme.sh --issue -w /path/to/www/htmlRoot/ -d example.com -k 2048

  1. –issue :颁发新证书。
  2. -w /DocumentRootPath/ :指定用于Web根模式的Web根文件夹。
  3. -d example.com :指定一个域,用于发布,续订或撤销等。可以多次使用。
  4. -k 2048 :指定域密钥的长度。

要为theos.in和www.theos.in颁发证书,请输入:
# acme.sh --issue -w /var/www/html -d theos.in -d www.theos.in

例如,如果将“ key-length”设置为“ no”,它将使用默认长度2048。在此示例中,将“ key-length”设置为4096个
# acme.sh --issue -w /var/www/html -d theos.in -d www.theos.in -k 4096

使用阿里云域API自动颁发证书

首先,您需要登录到Aliyun帐户以获取API密钥。 https://ak-console.aliyun.com/#/accesskey

1
2
export Ali_Key="sdfsdfsdfljlbjkljlkjsdfoiwje"
export Ali_Secret="jlsdflanljkljlfdsaklkjflsa"

好的,让我们现在颁发证书:

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

Ali_KeyAli_Secret将被保存~/.acme.sh/account.conf,需要时会被重用。

参考资料:https://github.com/acmesh-official/acme.sh/wiki/dnsapi

将颁发的证书安装到Nginx Web服务器

键入以下命令:
# acme.sh --installcert -d theos.in --keypath /etc/nginx/ssl/theos.in/theos.in.key --fullchainpath /etc/nginx/ssl/theos.in/theos.in.cer --reloadcmd 'systemctl reload nginx'
或 示例输出:
# acme.sh --install-cert -d theos.in \--key-file /etc/nginx/ssl/theos.in/theos.in.key \--fullchain-file /etc/nginx/ssl/theos.in/theos.in.cer \--reloadcmd 'systemctl reload nginx'

1
2
3
4
[UTC 2016年9月2日15:19:56 UTC安装密钥:/etc/nginx/ssl/theos.in/theos.in.key
[2016年9月2日星期五15:19:56 UTC]将完整链安装到:/etc/nginx/ssl/theos.in/theos.in.cer
[2016年9月2日星期五15:19:56 UTC]运行Le_ReloadCmd:systemctl重新加载nginx
[UTC 2016年9月2日星期五15:19:56]重新加载成功

哪里,

  1. –install-cert :将颁发的证书安装到nginx服务器

  2. -d theos.in :指定一个域,用于发布,续订或撤销等

  3. –key-file /etc/nginx/ssl/theos.in/theos.in.key :发布/续订后,密钥将被复制到此路径

  4. –fullchain-file /etc/nginx/ssl/theos.in/theos.in.cer :颁发/续订后,全链证书将被复制到此路径。

  5. –reloadcmd ‘systemctl reload nginx’ :发布/续订后,用于重新加载服务器

  6. 如何续订证书?

  7. 键入以下命令:
    # acme.sh --renew -d theos.in
    示例输出:

  8. ```
    [UTC 2016年9月2日星期五15:23:16]续订:“ theos.in”
    [2016年9月2日星期五15:23:16 UTC]跳过,下一个续订时间是:2016年11月21日星期一11月21日
    [UTC 2016年9月2日星期五15:23:16]添加’–force’以强制更新。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15



    1. ## 如何升级acme.sh客户端?

    2. 键入以下命令以将acme.sh客户端升级到来自https://github.com/Neilpang/acme.sh
    `# acme.sh --upgrade`

    3. `acme.sh --upgrade --auto-upgrade`
    之后, acme.sh 就会自动保持更新了.

    4. 你也可以随时关闭自动更新

    5. > ```
    > acme.sh --upgrade --auto-upgrade 0
  9. 示例输出的最新代码:

  10. ```
    [UTC 2016年12月24日星期六17:22:50]从在线存档安装。
    [UTC 2016年12月24日星期六17:22:50]下载https://github.com/Neilpang/acme.sh/archive/master.tar.gz
    [UTC 2016年12月24日星期六17:22:55]提取master.tar.gz
    [UTC 2016年12月24日星期六17:22:56]安装到/root/.acme.sh
    [UTC 2016年12月24日星期六17:22:56]安装到/root/.acme.sh/acme.sh
    [UTC 2016年12月24日星期六17:22:56]将别名安装到’/root/.bashrc’
    [UTC 2016年12月24日星期六17:22:56]确定,关闭并重新打开终端以开始使用acme.sh
    [2016年12月24日星期六,世界标准时间(UTC)]很好,可以找到bash,因此请更改shebang以使用bash作为首选。
    [UTC 2016年12月24日星期六17:22:56]确定
    [UTC 2016年12月24日星期六17:22:56]安装成功!
    [UTC 2016年12月24日星期六17:22:56]升级成功!

    1
    2
    3
    4
    5
    6
    7

    3. ### 有关Cron工作的说明

    4. 计划[工作也会尝试为您续订证书](https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/)。默认情况下按如下方式安装(您无需采取任何措施):

    5. ```shell
    0 0 * * *“ /root/.acme.sh"/acme.sh --cron --home” /root/.acme.sh“> / dev / null

acme.sh –install-cert -d theos.in
–key-file /etc/nginx/ssl/theos.in/theos.in.key
–fullchain-file /etc/nginx/ssl/theos.in/theos.in.cer
–reloadcmd ‘systemctl reload nginx’

  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

扫一扫,分享到微信

微信分享二维码

请我喝杯咖啡吧~

支付宝
微信